How to JSONify GraphQL Mutation query, and how to implement juniper trait


I'm learning GraphQL with the juniper crate and I'm trying to send Mutations encoded as JSON to the GraphQL server. I have two questions because the answer for one may solve the problem for the other.

I created the JSONified Mutation query using this Rust code.

When I print out the JSON result, I get this.

After I POST the request, I receive this for the error.

So now my questions:

  1. Is the JSONified Mutation query in the correct format?
  2. I don't fully understand the error message sent back by the server; I'm thinking that it's telling me that the Owner data type to use as an input type to a Mutation. How can I make it a valid input type, if so? I see that GraphQL has the concept of Scalars, and juniper has traits like ToInputValue, and I'm wondering if it's possible to do so for Owner, but I'm a bit lost on how to implement the trait.


Your mutation_query.json contains a bunch of returns, "\n", in the "query" field.

This is not valid JSON. At least JSON.parse in node.js does not like it and it looks all wrong to me.

Hello @ZiCog. Thanks for your response. I believe those returns are more a feature of how JSON is formatted to print in the serde_json crate than invalid JSON. I've run queries before that do not error out, so I'm almost certain that isn't the issue in this case.

For any who may happen to come across a similar problem, I was able to solve problem 2. I eventually found the GraphQLInputObject trait, which can be auto-derived for your custom data types. All members of your custom data type must implement GraphQLType.