Reputation: 65
I'm new to graphql specially graphql-java I have done queries with arguments successfully but when I try to send a mutation query the schema does not even execute the datafetcher is like not even been evaluated by the server. this is some snippets of my code.
DataFetcher nodeCreateDataFetcher = new DataFetcher(){
public Object get(DataFetchingEnvironment environment) {
Map source = (Map) environment.getSource();
String alias = (String) source.get("alias");
System.out.println(alias);
//This statement adds a new node with a name on an alias class field
Node node = getNodes.addNode(alias);
return node;
}
};
// Creates an InputobjectType
public GraphQLInputObjectType createNodeInputType(){
return newInputObject()
.name("nodeInput")
.field(newInputObjectField()
.name("alias")
.type(GraphQLString))
.build();
}
//Creates the Mutation schema
public GraphQLObjectType createMutation(){
return newObject()
.name("Mutation")
.field(newFieldDefinition()
.name("create")
.type(createNodeType())
.argument(newArgument()
.name("node")
.type(createNodeInputType())
.defaultValue("{alias: \"node4\"}"))
.dataFetcher(nodeCreateDataFetcher))
.build();
}
So I go to postman and write something like this {create(node:{alias:"anything"})}
this seems to be wrongs I see people using variable most of the time in graphql queries but I'm trying to do the simples mutation query and then start from there. I would really appreciate you help.
Upvotes: 0
Views: 2516
Reputation: 65
I just overlooked one important part of the specification actually I had to write mutation before the query like mutation {create(node:{alias:"anything"})}
Upvotes: 2