[英]GraphQL query error -- variable is never used in operation
I am performing a request for an individual post from Apollo Server / Express backend.我正在执行来自 Apollo Server / Express 后端的单个帖子的请求。
In the Apollo GraphQL sandbox, the query works and retrieves the correct post, however, the query has a red squiggle identifying an error which reads -在 Apollo GraphQL 沙箱中,查询工作并检索到正确的帖子,但是,查询有一个红色波浪线标识错误,内容为 -
Variable "$getPostId" is never used in operation "Query".
变量“$getPostId”从未在“查询”操作中使用。
The query is as follows -查询如下——
query Query($getPostId: ID!) {
getPost(id:"20c9b3ac-afe6-4faa-a3f9-e00ef1b38ccf") {
title
author
id
}
}
The schema is as follows -架构如下 -
module.exports = gql`
type Post {
id: ID!
title: String!
author: String!
}
type Query {
getPosts: [Post]!
getPost(id: ID!): Post
}
...
`
The closest post which seems to address a similar problem I could find is here .似乎解决了我能找到的类似问题的最接近的帖子是here 。 However, I can't translate the resolution to my problem.
但是,我无法将解决方案转化为我的问题。
Why is the error showing (particularly when the query runs successfully)?为什么会显示错误(尤其是在查询成功运行时)? What needs to be done to stop the error from showing?
需要做什么来阻止错误显示?
Many thanks!非常感谢!
It sounds like这听起来像
query Query($getPostId: ID!) {
getPost(id:"20c9b3ac-afe6-4faa-a3f9-e00ef1b38ccf") {
title
author
id
}
}
is supposed to be应该是
query Query($getPostId: ID!) {
getPost(id: $getPostId) {
title
author
id
}
}
Or if your query is actually meant to hard-code the ID, then you want或者,如果您的查询实际上是对 ID 进行硬编码,那么您想要
query Query {
getPost(id:"20c9b3ac-afe6-4faa-a3f9-e00ef1b38ccf") {
title
author
id
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.