graphql-java-kickstart/graphql-spring-webclient

handling algebraic data types in response

weijuly opened this issue · 1 comments

Describe the bug
My GraphQL query request is as below:

query {
    searchAuthorById(authorId: "d43680eb-8e54-11ec-a8fb-0242ac150002") {
        ... on Author {
            id
            firstName
            lastName
        }
        ... on BookStoreError {
            status
            message
        }
    }
}

When I get the response as GraphQLResponse object how do I check if the response is an Author object or a BookStoreError object ?

GraphQLRequest request = GraphQLRequest.builder().query(query).build();
GraphQLResponse response = graphQLWebClient.post(request).block();
response.get("searchAuthorById", ???);

To Reproduce
Steps to reproduce the behaviour:
Try parsing response from a GraphQL server that produces ADT response

Expected behavior
GraphQLResponse should have a way to check what type of data is being returned

Screenshots
NA

Desktop (please complete the following information):

  • OS: Mac OS X
  • Browser: Chrome
  • Version: latest

Additional context
Add any other context about the problem here.

Apparently, from the response, there's no way to identify the type ...