首页 > 解决方案 > Custom GraphQL schema in Strapi#beta.3 is not working

问题描述

We have just upgraded our project to Strapi version 3-beta, and the GraphQL schema that we have defined for user model in /extensions/users-permissions/config/schema.graphql is not working anymore, it's like this file is being ignored. It used to work in the latest alpha version #alpha.26.

Here is the schema /extensions/users-permissions/config/schema.graphql:

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

Here is the query that will get sent to GraphQL endpoint:

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

Here is the error, when we request to that query:

{
    "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)"
                    ]
                }
            }
        }
    ]
}

标签: javascriptnode.jsgraphqlstrapi

解决方案


它现在已在Strapi@beta-4中修复

错误修复

  • [插件] 在 graphql 模式中加载扩展(#3417)@alexandrebodin
  • ...

推荐阅读