Reputation: 103
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.
Upvotes: 5
Views: 19269
Reputation: 1
In JavaScript, there is a single numeric type, which is represented as a double-precision floating-point number according to the ECMAScript specification. This means that all numeric values in JavaScript are stored as floats, even if they look like integers. so when converting number type convert into a Float type not Int
Upvotes: 0
Reputation: 81
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.
Upvotes: 3
Reputation: 9
I fixed this by changing the variable type of ID from Int
to Float
Upvotes: 0