I'm testing graph-spqr librabry in a simple java program.
This is what I've done so far:
public class GraphQLResolver {
private String status;
private Integer price;
@GraphQLMutation(name="updateStatusOrder")
public void updateStatusOrder(@GraphQLArgument(name="id") String orderId,@GraphQLArgument(name="status") String status) {
//to do
}
@GraphQLQuery(name="getStatus")
public String getStatus(@GraphQLArgument(name="id") String orderId) {
this.status="Example of status";
return this.status;
}
}
Then, I calling building GraphQL methods in main method
public class Main {
public static void main(String[] args) {
GraphQLSchema schema = new GraphQLSchemaGenerator()
.withOperationsFromSingleton(new GraphQLResolver())
.generate(); //done ;)
GraphQL graphQL = new GraphQL.Builder(schema).build();
ExecutionResult result = null;
result = graphQL.execute("{getstatus(id:123){status}}");
}
}
I have error : Query failed to validate : '{status(id:123){status}}'
What is wrong?
I guess the correct query should be :
{
getstatus(id:"123")
}
with the following reasons :
You define the id argument as String , so need to use double quote around the argument value.
The getStatus
query is defined to return a String
which is a scalar but not an object type in term of GraphQL. So you don't need to further define what of its fields to be returned as the scalar does not have any fields for you to pick.