0

I’ve got a question I can’t seemingly resolve on my own.

Together with basic Query, Mutation and so on types I’ve made the following type definition:

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

And I then try to query it with:

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
  }
}

And I pass the following as query variables:

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

The problem is it bails out with the following:

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

I honestly have no clue why it complains about the Int type…

If I get rid of the problematic $first query variable in the request, it works fine.

This:

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

Produces this:

{
  "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"
    }
  }
}

Any hints, ideas on how to fix this? I use the graphql gem v1.6.3.

eploko
  • 5,347
  • 2
  • 28
  • 23
  • Did you solve your problem? I have the same error message despite the type is defined in schema... – nattfodd Jan 24 '18 at 13:33
  • Hey, @nattfodd, pls check out the accepted answer below. AFAIK, the fix for the issue has been merged and should have been released since. If you still run into the same issue, I reckon, re-opening the issue may be a way to go. – eploko Jan 30 '18 at 15:14

1 Answers1

0

Currently, there seems to be a bug in graphql-ruby that prevents types not explicitly used in a schema from being propagated. Check out this issue on GitHub: https://github.com/rmosolgo/graphql-ruby/issues/788#issuecomment-308996229

To fix the error one has to include an Int field somewhere in the schema. Turns out I haven't had one. Yikes.

This fixed it for me:

# Make sure Int is included in the schema:
field :testInt, types.Int
eploko
  • 5,347
  • 2
  • 28
  • 23