americanexpress / nodes

A GraphQL JVM Client - Java, Kotlin, Scala, etc.
Apache License 2.0
307 stars 70 forks source link

Mutation query returning Boolean throws Exception #80

Closed bhardwajankur3 closed 5 years ago

bhardwajankur3 commented 5 years ago

I have a mutation query which returns a Boolean. The following POJO does not work:

@GraphQLProperty(name = "updateHealth", arguments = {@GraphQLArgument(name = "request")}) `public class UpdateHealth { private boolean isSuccess;

public boolean isSuccess() {
    return isSuccess;
}

public void setSuccess(boolean isSuccess) {
    this.isSuccess = isSuccess;
}

}`

I get the following error: Validation error of type SubSelectionNotAllowed: Sub selection not allowed on leaf type Boolean of field updateHealth @ 'updateHealth''.

It generates the following query: query { updateHealth (request:{apiStatusDetails:[{apiPath:"/v1/sampleextensionapi/health",httpMethod:"GET",status:AVAILABLE},{apiPath:"/v1/sampleextensionapi/sampleresource/hello",httpMethod:"GET",status:AVAILABLE}],extName:"hello-world",status:AVAILABLE}) { isSuccess } }

On the graphql console, when I run the query WITHOUT {isSuccess} at the end, it works. How do I do it programmatically? Here is how I am setting things up:

`List apiDetails = new ArrayList();

for (ApiStatusDetails detail : response.getApiStatusDetails()) { InputObject apiDetail = new InputObject.Builder().put("apiPath", detail.getApiPath()) .put("httpMethod", detail.getHttpMethod()).put("status", detail.getStatus()).build(); apiDetails.add(apiDetail); }

InputObject request = new InputObject.Builder().put("extName", response.getExtensionName()) .put("status", response.getStatus()).put("apiStatusDetails", apiDetails).build();

GraphQLRequestEntity requestEntity = GraphQLRequestEntity.Builder() .url("http://localhost:8443/v1/console/graphql") .arguments(new Arguments("updateHealth", new Argument<>("request", request))) .request(UpdateHealth.class) .build(); System.out.println(requestEntity.getRequest());

GraphQLResponseEntity responseEntity = graphQLTemplate.mutate(requestEntity, UpdateHealth.class);`

bhardwajankur3 commented 5 years ago

It worked. Instead of GraphQLResponseEntity<UpdateHealth> responseEntity = graphQLTemplate.mutate(requestEntity, UpdateHealth.class);, I had to mention Boolean i.e., GraphQLResponseEntity<Boolean> responseEntity = graphQLTemplate.mutate(requestEntity, Boolean.class);