GraphQL deliminates string literals using double quotation marks ("
). If you need to use a string literal with one or more double quotation mark characters inside it, you need to correctly escape those characters by inserting a backslash (\
) before each one. If you don't do this, GraphQL treats the double quotation mark inside the string as the terminator for the entire string, and normally the next character in your string ends up creating a syntax error.
So a string value like this:
{"key": "value"}
needs to be escaped like this:
{\"key\": \"value\"}
as a literal inside your GraphQL document, it ends up looking like this:
"{\"key\": \"value\"}"
The same rule also applies to strings you send as variables, but this is due to JSON syntax rules, not GraphQL ones. You can read up more about escaping characters inside strings in the spec.