3
votes

I've got a graphql server implemented with graphql-go, and I'm using Apollo on the front end. Simple queries without arguments, and mutations using input object types work fine, but for some reason passing a scalar type argument in a query returns the error:

[{"message":"Unknown type \"Int\".","locations":[{"line":1,"column":19}]}]

My use could not be simpler; on the client side, my query is:

export const GET_CLIENT = gql`
  query client($id: Int) {
  client(id: $id) {
    id
    name
  }
}`

which is used in a component like so:

<Query
  query={GET_CLIENT}
  variables={{
    id: 1
  }} />

which resolves to this field on the backend:

// ClientQuery takes an ID and returns one client or nil
var ClientQuery = &graphql.Field{
Type: ClientType,
Args: graphql.FieldConfigArgument{
    "id": &graphql.ArgumentConfig{
        Type: graphql.Int,
    },
},
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
    return p.Context.Value("service").(*model.Service).FindClientByID(id)
},
}

I've tried passing input objects, strings, etc. but it seems that no query arguments, scalar or otherwise are ever satisfied on the backend. I've tried both master and v0.7.5 of graphql-go. Am I missing something? Help very much appreciated, it feels weird for something this basic to be such a huge blocker.

2
Did you ever figure this out? I ran into a similar error and mine turned out to be caused by a different error hidden in the query. Using your query as a start, my mistake was that the id argument was actually named something else. Once I fixed my query so that other mistakes were gone, the error about Int was also goneMatt Lavin
I never did figure it out, but I'll try this, thank you for the ping.slowcode
I've hit this a couple of times since commenting. In every case, my query was wrong in some other way. I think it's just bad error reporting in the graphql toolsMatt Lavin

2 Answers

1
votes

As the other post that mentioned having to go from int to float, this error occurs because the types set up in your graphQL schema are conflicting with the types you are trying to use when querying.

It's saying: 'Unknown type Int'

But what it really means is: 'Expected type Float but got Int' then you'd go change it where it is wrong.

0
votes

I fixed this by changing the variable type of ID from Int to Float