2017-06-16 133 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