ID handling not dealing with integer values - bug?

21 views
Skip to first unread message

Alan Boshier

unread,
Nov 18, 2016, 7:57:51 AM11/18/16
to graphql-java
With the following schema query definition

final GraphQLObjectType queryType = newObject()
       
.name("QueryType")
       
.field(newFieldDefinition()
           
.name("foo")
           
.type(Foo)
           
.argument(newArgument()
               
.name("id")
               
.description("The id of the foo")
               
.type(new GraphQLNonNull(GraphQLID)))
           
.dataFetcher(getFetcherForResource("foo")))
           
.build();

The query

{ foo(id:"1") { id bar } }

works ok, but the query

{ foo(id:1) { id bar } }

fails with

{"errors":[{"validationErrorType":"WrongType","message":"Validation error of type WrongType: argument value IntValue{value=1} has wrong type","locations":[{"line":1,"column":10}],"errorType":"ValidationError"}],"data":null}


According to the GraphQL spec:

When expected as an input type, any string (such as "4") or integer (such as 4) input value should be coerced to ID as appropriate for the ID formats a given GraphQL server expects. Any other input value, including float input values (such as 4.0), must raise a query error indicating an incorrect type.

Also, if attempt to populate my response object to this query with a numeric value, it appears in the JSON result as null rather than a stringified form of that value. Again I believe the GraphQL spec states that servers should coerce results as appropriate before serializing ID values to JSON strings.

Is there some way to configure the graphql server to accept numeric-format ID values?

Thanks

Alan


Peace MICHAELS

unread,
Nov 18, 2016, 6:03:26 PM11/18/16
to graphql-java
please raise an issue on gitbub

Alan Boshier

unread,
Nov 19, 2016, 3:12:40 AM11/19/16
to graphql-java
Thanks - now raised as issue 244.
Reply all
Reply to author
Forward
0 new messages