简体   繁体   English

GraphQL 查询错误——变量从未在操作中使用

[英]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.

相关问题 Gatsby GraphQL错误:变量“ $ slug”从未在操作“ BlogPostQuery”中使用 - Gatsby GraphQL error: Variable “$slug” is never used in operation “BlogPostQuery” 变量“$productSlug”从未在“SingleProduct”操作中使用。 Graphql 错误。 变量在我的 Gatsby graphql 查询中不起作用 - Variable "$productSlug" is never used in operation "SingleProduct". Graphql error. Variables are not working in my Gatsby graphql queries “错误:错误解码签名”和“变量 '$token' 从未在操作 'VerifyToken' 中使用。” - "Error: Error decoding signature" and "Variable '$token' is never used in operation 'VerifyToken'." 在 Gatsby 模板的查询中引用 GraphQL 变量? - Referencing GraphQL variable used in query in Gatsby template? GraphQL:变量被匿名查询使用但未声明 - GraphQL: Variable is used by anonymous query but not declared GraphQL - 未由操作定义的变量 - GraphQL - variable not defined by operation 将变量解析为GraphQL查询时出现错误400 - Error 400 when parsing variable to GraphQL query Flutter 将变量传递给 GraphQl 查询并出现错误 - Flutter passing variable to GraphQl query and getting error Apollo客户端Graphql查询变量类型错误 - Apollo client Graphql query variable type error Flutter graphql 查询带变量 - Flutter graphql query with variable
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM