Type mismatch on variable and argument (Int / Int)

Viewed 1689

Given the following GraphQL request and variables:

Request:

query accounts($filter:AccountFilter, $first_:String, $skip_:Int) {
  accounts(filter: $filter, first: $first_, skip: $skip_) {
    id
  }
}

Variables:

{
  "filter": {},
  "first_": "3",
  "skip_": 0
}

Note: I added underscores to the first_ and skip_ variable names to help distinguish them from the arguments first and skip.

I'm getting the following errors:

"Type mismatch on variable $first_ and argument first (String / Int)"

"Type mismatch on variable $skip_ and argument skip (Int / Int)"

The first error I created on purpose as a sanity check. The value in the variables should be "first": 3, and not "first": "3",. The second error I don't understand why I'm getting it. How is Int and Int Type mismatched? The first variable/argument error reoprts the same error (Int / Int) when I correctly pass 3 and change String to Int.

What am I doing wrong?

Backend Specs: Ruby on Rails

Argument Specs:

"""
Interface for the Account model
"""
type Account {
  friendlyId: String!
  id: ID!
  locations: [Location!]!
  name: String!
  participants: [User!]!
  primaryLocation: Location!
  primarySiteContact: User!
  siteContacts: [User!]!
}

input AccountFilter {
  OR: [AccountFilter!]
}

type Query {
  """
  Details for an Account
  """
  accountDetails(id: ID): Account

  """
  A list of Accounts
  """
  accounts(filter: AccountFilter, first: Int, skip: Int): [Account!]
}
1 Answers

So this is(was) a known issue with graphql for Ruby. The issue seems to have a PR and fix avaiable but I'm still having this issue even after updating my graphql gem.

You can view the issue here: https://github.com/rmosolgo/graphql-ruby/issues/2784

The fix that works for me included in that post is here:

def self.type_from_ast(*args)
  type = super
  type == GraphQL::Types::Int ? type.to_graphql : type
end
Related