我正在尝试在最新的 apollo/server 4.9 和 graphqlClient - 3.7 中进行这样的查询,如下所示:
const USER_DATA = gql`
query getUserData($subdomain: String!) {
getUserData(subdomain: $subdomain) {
_id
full_name
email
valid_complex_password
projects {
_id
image_url
title
description
street_address
city
province
country
}
}
}
但继续得到这个:
{
"errors": [
{
"message": "Cannot query field \"getUserData\" on type \"Query\".",
"locations": [
{
"line": 2,
"column": 3
}
],
"extensions": {
"code": "GRAPHQL_VALIDATION_FAILED",
"stacktrace": [
"GraphQLError: Cannot query field \"getUserData\" on type \"Query\".",
......
]
}
}
]
}
同样的查询过去可以在旧版本的 apollo 服务器/客户端和 graphql 上正常工作。升级后,它开始崩溃,而无需对架构等进行任何更改。
查询方式有什么需要更改的或者我遗漏了什么吗?
迁移自
"apollo-server-errors": "^3.3.1",
"apollo-server-express": "^2.16.1",
"apollo-upload-server": "^7.1.0",
"graphql": "^14.6.0",
"graphql-compose": "^7.17.0",
"graphql-compose-aws": "^4.0.1",
"graphql-compose-connection": "^6.2.0",
"graphql-compose-mongoose": "^7.3.8",
"graphql-middleware": "^4.0.2",
"graphql-redis-subscriptions": "^2.2.2",
"graphql-tools": "^4.0.8",
至
"@apollo/server": "^4.9.5",
"graphql": "^16.8.1",
"graphql-compose": "^9.0.10",
"graphql-compose-aws": "^5.3.0",
"graphql-compose-connection": "^8.2.1",
"graphql-compose-mongoose": "^10.0.0",
"graphql-middleware": "^6.1.35",
"graphql-redis-subscriptions": "^2.6.0",
"graphql-subscriptions": "^2.0.0",
简短的回答是,您已经在 Apollo-server 中跨 2 个版本的重大更改进行了迁移。您需要迁移您的项目才能使其在 apollo-server v4.x 世界中工作。
如果您不使用 Express 来提供任何其他内容,我建议仅使用 apollo-server 并放弃 Express。 v4 中使用 Apollo 和 Express 的模型有很大不同。