americanexpress / nodes

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

How to response pack as class #89

Closed ghost closed 5 years ago

ghost commented 5 years ago

mutation { createUser( userData: { firstName: "Bullhorn", lastName: "Pegas"

}) {

user{

firstName lastName } } }

InputObject inputObject = new InputObject.Builder<>().put("firstName", "myname").put("lastName", "Sujith") .build(); GraphQLRequestEntity build = GraphQLRequestEntity.Builder().url("http://192.168.0.182:8000/graphql/") .requestMethod(GraphQLMethod.MUTATE) .arguments(new Arguments("createUser", new Argument<>("userData", inputObject))) .request(TestClass.class).build(); GraphQLTemplate graphQLTemplate = new GraphQLTemplate(); System.err.println("Sending request " + build.getRequest()); GraphQLResponseEntity execute = graphQLTemplate.mutate(build, TestResponse.class);

import io.aexp.nodes.graphql.annotations.GraphQLArgument; import io.aexp.nodes.graphql.annotations.GraphQLProperty; @getter @setter @GraphQLProperty(arguments = { @GraphQLArgument(name = "firstName"), @GraphQLArgument(name = "lastName") },name = "createUser") public class TestResponse { private String firstName; private String lastName; }

import io.aexp.nodes.graphql.annotations.GraphQLArgument; import io.aexp.nodes.graphql.annotations.GraphQLProperty;

@GraphQLProperty(name = "createUser", arguments = { @GraphQLArgument(name = "userData") }) @getter @setter public class TestClass {

private String firstName;
private String lastName;

}

chemdrew commented 5 years ago

check out this article for more examples of how to set arguments