Strapi GraphQL覆盖

时间:2018-05-11 17:29:51

标签: graphql strapi

我试图重写我的GraphQL架构,以便所有内容都来自" top query"。例如,我有耐心,地点,实践内容类型。但我希望每个查询都以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]
}

任何想法如何实现这一目标?谢谢!

1 个答案:

答案 0 :(得分: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
    }
  }
};