【问题标题】:graphql-ruby: Int isn't a defined input type (on $first)graphql-ruby:Int 不是定义的输入类型(在 $first 上)
【发布时间】:2017-11-19 02:52:34
【问题描述】:

我有一个似乎无法靠自己解决的问题。

连同基本的Query、Mutation等类型我做了如下类型定义:

module Types
  UserType = GraphQL::ObjectType.define do
    name 'User'
    description 'A user'

    implements GraphQL::Relay::Node.interface
    global_id_field :id

    field :email, !types.String, 'Email address'

    connection :docs, DocType.connection_type, 'Available docs'
  end  
end

然后我尝试使用以下方式查询它:

query FileListQuery(
  $after: String
  $first: Int
) {
  viewer {
    currentUser {
      docs(first: $first, after: $after) {
        edges {
          node {
            id
            name
            __typename
          }
          cursor
        }
        pageInfo {
          endCursor
          hasNextPage
          hasPreviousPage
          startCursor
        }
      }
      id
    }
    id
  }
}

我将以下内容作为查询变量传递:

{
  "first": 1,
  "after": null
}

问题在于它通过以下方式摆脱困境:

{
  "errors": [
    {
      "message": "Int isn't a defined input type (on $first)",
      "locations": [
        {
          "line": 3,
          "column": 3
        }
      ],
      "fields": [
        "query FileListQuery"
      ]
    }
  ]
}

老实说,我不知道它为什么抱怨 Int 类型……

如果我去掉请求中有问题的$first 查询变量,它就可以正常工作。

这个:

query FileListQuery(
  $after: String
) {
  viewer {
    currentUser {
      docs(first: 10, after: $after) {
        edges {
          node {
            id
            name
            __typename
          }
          cursor
        }
        pageInfo {
          endCursor
          hasNextPage
          hasPreviousPage
          startCursor
        }
      }
      id
    }
    id
  }
}

产生这个:

{
  "data": {
    "viewer": {
      "currentUser": {
        "docs": {
          "edges": [
            {
              "node": {
                "id": "1",
                "name": "First Doc",
                "__typename": "Doc"
              },
              "cursor": "MQ=="
            }
          ],
          "pageInfo": {
            "endCursor": "MQ==",
            "hasNextPage": false,
            "hasPreviousPage": false,
            "startCursor": "MQ=="
          }
        },
        "id": "1"
      },
      "id": "VIEWER"
    }
  }
}

关于如何解决这个问题的任何提示和想法?我使用的是 graphql gem v1.6.3。

【问题讨论】:

  • 您的问题解决了吗?尽管模式中定义了类型,但我收到相同的错误消息...
  • 嘿,@nattfodd,请查看下面接受的答案。 AFAIK,该问题的修复程序已经合并,应该已经发布了。如果你仍然遇到同样的问题,我认为,重新打开问题可能是一种方法。

标签: ruby-on-rails ruby graphql graphql-ruby


【解决方案1】:

目前,graphql-ruby 中似乎存在一个错误,该错误会阻止传播模式中未明确使用的类型。在 GitHub 上查看此问题:https://github.com/rmosolgo/graphql-ruby/issues/788#issuecomment-308996229

要修复错误,必须在架构中的某处包含Int 字段。原来我一个都没有。哎呀。

这为我解决了问题:

# Make sure Int is included in the schema:
field :testInt, types.Int

【讨论】:

  • 这对我没有任何作用。
猜你喜欢
  • 2020-03-21
  • 2017-06-04
  • 1970-01-01
  • 2019-03-15
  • 2016-10-14
  • 2020-01-09
  • 2018-06-30
  • 2020-04-20
相关资源
最近更新 更多