I know this isn't so much a graphql-dotnet issue as a NewtonSoft issue but may help someone (or I likely am missing something).
I'm trying to deserialize where the queryargument is a string:
var body = "{\"query\":\"{transactions(term:\"hello\") {transactionId}}\"}"
var request = JsonConvert.DeserializeObject<GraphQLQuery>(body);
But NewtonSoft baulks at the 'h' in 'hello':
"After parsing a value an unexpected character was encountered: h. Path 'query', line 1, position 30."
How do you get around this?
Passing IntGraphType as below works fine.
var body = "{\"query\":\"{documents(typeId:1) {documentId, documentName, description, revision}}\"}
Thanks for any/all responses.
var body = "{\"query\":\"{transactions(term:\"hello\") {transactionId}}\"}"
That is invalid JSON (which is why you get the parse error). To properly escape the " around hello you have to include the escaped \.
var body = "{\"query\":\"{transactions(term:\\\"hello\\\") {transactionId}}\"}"
You can see the required JSON format by reversing the process:
var data = new GraphQLQuery
{
Query = "{transactions(term:\"hello\") {transactionId}}"
};
var body2 = JsonConvert.SerializeObject(data);
Most helpful comment
That is invalid JSON (which is why you get the parse error). To properly escape the
"aroundhelloyou have to include the escaped\.You can see the required JSON format by reversing the process: