0

我正在尝试重写我的 GraphQL 模式,以便一切都来自“顶级查询”。例如,我有耐心、地点、实践的内容类型。但我希望每个查询都location { // rest of query以防止人们检查不属于他们的东西开始。为了实现这一点,我一直在将 schema.graphql 添加到我的所有模型中

然后,我想从实践中删除对所有内容的访问权限并覆盖 findOne 以排除参数,并且只是practice控制器将在其中使用当前用户的状态填写 ID。

module.exports = {
  query: `
    practice: Practice
  `,
  resolver: {
    Query: {
      practice: {
        description: 'Return the practice of the authenticated user',
        resolver: 'Practice.findMine'
      },
      practices: false
    }
  }
};

我无法使之前的代码工作,因为 GraphQl 带有内部错误,说我只能指定一次练习。即使如此,在生成的模式中似乎并非如此

type Query {
  practice: Practice
  files(sort: String, limit: Int, start: Int, where: JSON): [UploadFile]
  role(id: String!): UsersPermissionsRole

  """
  Retrieve all the existing roles. You can't apply filters on this query.
  """
  roles(sort: String, limit: Int, start: Int, where: JSON): [UsersPermissionsRole]
  user(id: String!): UsersPermissionsUser
  users(sort: String, limit: Int, start: Int, where: JSON): [UsersPermissionsUser]
}

任何想法如何做到这一点?谢谢!

4

1 回答 1

0

我是 Strapi 的联合创始人之一。你能试试这个吗?我认为您需要禁用练习类型的影子 CRUD 功能。

module.exports = {
  definition: ``,
  query: `
    practice: Practice
  `,
  type: {
    Practice: false
  }
  resolver: {
    Query: {
      practice: {
        description: 'Return the practice of the authenticated user',
        resolver: 'Practice.findMine'
      },
      practices: false
    }
  }
};
于 2018-05-15T15:15:45.813 回答