【问题标题】:Variable is defined but GraphQL cannot find it变量已定义,但 GraphQL 找不到它
【发布时间】:2020-11-04 23:53:44
【问题描述】:

刚学GraphQL,我有这样的查询:

query OrganizationForFacebook($organization: String!, $repository: String!) {
  organization(login: $organization) {
    name
    url
    repository(name: $repository) {
      name
      forkCount @include(if: $withFork)
    }
  }
}

我已经这样定义了我的变量:

{
  "organization" : "the-road-to-learn-react",
  "repository" :"the-road-to-learn-react-chinese",
  "withFork" : true
}

问题在于“withFork”的说法

""message": "变量 $withFork 被 OrganizationForFacebook 使用,但是 未声明”

但我不是在那儿声明了吗?那有什么问题呢?

【问题讨论】:

    标签: graphql


    【解决方案1】:

    您只声明了两个变量作为操作的一部分:

    $organization: String!, $repository: String!
    

    您还需要添加$withFork: Boolean!

    【讨论】:

    • 哦,在顶部。好的,我添加了它。谢谢。现在工作。 GraphQL 真是个不错的发明!我很喜欢学习它。
    猜你喜欢
    • 2023-03-16
    • 1970-01-01
    • 2018-08-06
    • 1970-01-01
    • 1970-01-01
    • 2020-11-30
    • 1970-01-01
    • 2016-02-29
    • 2014-10-09
    相关资源
    最近更新 更多