graphql-java-kickstart/graphql-spring-webclient

Getting java.lang.IllegalArgumentException: Unrecognized field "errorType" exception when parsing error response

LiorAzar opened this issue · 4 comments

Hello,
first i just wanted to say thanks for this lib!! It's exactly what i was looking for.

Describe the bug
When parsing GraphQLError with the following response:
{"errors":[{"errorType":"DataFetchingException","locations":[{"line":1,"column":3,"sourceName":null}],"message":"bla","path":["bla"],"extensions":{"bla"}}],"data":{"bla":null}}

It throws the following error:
java.lang.IllegalArgumentException: Unrecognized field "errorType" (class graphql.kickstart.spring.webclient.boot.GraphQLError), not marked as ignorable (4 known properties: "extensions", "path", "locations", "message"]) at [Source: UNKNOWN; line: -1, column: -1] (through reference chain: java.util.ArrayList[0]->graphql.kickstart.spring.webclient.boot.GraphQLError["errorType"])

Shouldn't graphql.kickstart.spring.webclient.boot.GraphQLError matches the https://github.com/graphql-java/graphql-java/blob/dc2cdda7878efa04e74019ccce651df71ad7380c/src/main/java/graphql/GraphQLError.java#L21 interface?

To Reproduce
Steps to reproduce the behavior:
Send any request that will return an error with errorType:
GraphQLRequest request = graphQLRequestBuilder.query(query).build();
GraphQLResponse response = graphQLWebClient.post(request).block();

throws the following exception java.lang.IllegalArgumentException: Unrecognized field "errorType" (class graphql.kickstart.spring.webclient.boot.GraphQLError), not marked as ignorable (4 known properties: "extensions", "path", "locations", "message"]) at [Source: UNKNOWN; line: -1, column: -1] (through reference chain: java.util.ArrayList[0]->graphql.kickstart.spring.webclient.boot.GraphQLError["errorType"])

Expected behavior
return GraphQLResponse without any exceptions

@oliemansm Any thoughts on this issue?
currently I get the following exception:

Unrecognized field "errorType" (class graphql.kickstart.spring.webclient.boot.GraphQLError), not marked as ignorable (4 known properties: "extensions", "path", "locations", "message"])
 at [Source: UNKNOWN; line: -1, column: -1] (through reference chain: java.util.ArrayList[0]->graphql.kickstart.spring.webclient.boot.GraphQLError["errorType"])

we will keep getting this exception instead catching the real error if we don't, at least, add the JsonIgnoreProperties annotation

@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class GraphQLError {

  private String message;
  private List<Location> locations;
  private List<String> path;
  private Map<String, Object> extensions;

}

This implementation is according to the recommended error spec: https://spec.graphql.org/June2018/#sec-Errors. Custom fields like errorType should go in the extensions map instead of at root level.

We could and probably should add that ignore unknown properties annotation to prevent these kind of parsing errors.

I created a PR for the ignore properties
#29

Thanks!

Thanks!