shurcooL / graphql

Package graphql provides a GraphQL client implementation.
MIT License
709 stars 282 forks source link

Unmarshal data field only if present. #23

Closed dmitshur closed 6 years ago

dmitshur commented 6 years ago

The data field may not be present in the response from GraphQL server. This is valid according to GraphQL specification, section 7.2.1 (https://facebook.github.io/graphql/October2016/#sec-Data):

If an error was encountered before execution begins, the data entry should not be present in the result.

If it's not present, it won't have a valid JSON value. As a result, jsonutil.UnmarshalGraphQL will return an "unexpected end of JSON input" error, and prevent errors from the GraphQL response from being returned. We don't want that, so only try to Unmarshal the data value if it's present in the response.

Fixes #22.

mwilli31 commented 6 years ago

Validated this fix locally. All works now. Thanks!

It can be merged into master. @shurcooL Let me know if you need anything else.

dmitshur commented 6 years ago

Thanks for checking, @mwilli31.