2017-06-16 90 views
0

我有一个问题,我不能自己解决。

基本的查询

总之,突变等类型的我做了以下类型定义:

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。

+0

你有没有解决问题了吗?我有同样的错误消息,尽管类型是在架构中定义的... – nattfodd

+0

嗨,@nattfodd,请查看下面接受的答案。 AFAIK,这个问题的解决方案已经合并,应该从那以后发布。如果你仍然遇到同样的问题,我认为,重新开放这个问题可能是一种方法。 – eploko

回答

0

目前,似乎有一个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