javascript - 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)"
]
}
}
}
]
}
解决方案
它现在已在Strapi@beta-4中修复
错误修复
- [插件] 在 graphql 模式中加载扩展(#3417)@alexandrebodin
- ...
推荐阅读
- joomla3.0 - Joomla 自定义模块中的布局
- apache - 如果服务器安装了 nginx 和 apache,我如何找出它用于其网站的哪一个?
- azure - 从 Angular 前端调用受 Azure AD 保护的 Web API
- android - Admob 广告无法在 android 中加载
- php - 检测当前用户
- python - 在python中将字典转换为数据框
- canvas - 如何在 Flutter 画布中画一个十字?
- tmux - 如何使用一个命令启动多面板
- java - 将鼠标从当前位置移动到 JComponent 位置
- java - System.getProperty("user.home") 不起作用