Strapi#beta.3 中的自定义 GraphQL 模式不起作用

Custom GraphQL schema in Strapi#beta.3 is not working

我们刚刚将我们的项目升级到 Strapi 版本 3-beta,我们在 /extensions/users-permissions/config/schema.graphql 中为 user 模型定义的 GraphQL 模式不再起作用,就像这个文件正在被忽略。 它曾经在最新的 alpha 版本 #alpha.26.

中工作

这是架构 /extensions/users-permissions/config/schema.graphql:

module.exports = {
  query: `
    userSearch(_q: String!): [UsersPermissionsUser]
  `,
  resolver: {
    Query: {
      userSearch: {
        resolver: {
          plugin: 'users-permissions',
          handler: 'User.search'
        }
      },
    }
  }
};

这是将发送到 GraphQL 端点的查询:

query ($_q: String!) {
    userSearch(_q: $_q) {
        id
        first_name
        last_name
    }
}

这是错误,当我们请求该查询时:

{
    "errors": [
        {
            "message": "Cannot query field \"userSearch\" on type \"Query\". Did you mean \"users\"?",
            "locations": [{ "line": 2, "column": 3 }],
            "extensions": {
                "code": "GRAPHQL_VALIDATION_FAILED",
                "exception": {
                    "stacktrace": [
                        "GraphQLError: Cannot query field \"userSearch\" on type \"Query\". Did you mean \"users\"?",
                        "    at Object.Field (/project/node_modules/graphql/validation/rules/FieldsOnCorrectType.js:64:31)",
                        "    at Object.enter (/project/node_modules/graphql/language/visitor.js:332:29)",
                        "    at Object.enter (/project/node_modules/graphql/language/visitor.js:383:25)",
                        "    at visit (/project/node_modules/graphql/language/visitor.js:250:26)",
                        "    at Object.validate (/project/node_modules/graphql/validation/validate.js:63:22)",
                        "    at validate (/project/node_modules/apollo-server-core/dist/requestPipeline.js:211:32)",
                        "    at Object.<anonymous> (/project/node_modules/apollo-server-core/dist/requestPipeline.js:124:42)",
                        "    at Generator.next (<anonymous>)",
                        "    at fulfilled (/project/node_modules/apollo-server-core/dist/requestPipeline.js:4:58)",
                        "    at process._tickCallback (internal/process/next_tick.js:68:7)"
                    ]
                }
            }
        }
    ]
}

现在已修复 Strapi@beta-4

Bug fix

  • [Plugin] Load extensions in graphql schemas (#3417) @alexandrebodin
  • ...