Reputation: 471
My goal is to be able to pass a stringed object in a GraphQL query.
Goal:
{
accounts (filter:
'{"fieldName": "id",
"fieldValues":["123"],
"filterType":"in"}'){
id
}
}
Error:
"Syntax Error GraphQL request (1:22) Unexpected single quote character ('), did you mean to use a double quote (\")?"
Problem is GraphQL doesn't seem to accept strings surrounded with single quotes.
Using single quotes inside of the object won't be possible because this would require major changes to the client which compiles these objects.
Example:
{
"fieldName": "id",
"fieldValues":["123"],
"filterType":"in"
}
Schema:
accounts: {
type: new GraphQLList(accountType),
args: {
id: { type: GraphQLString },
status: { type: GraphQLString },
filter: { type: GraphQLString },
sort: { type: GraphQLString },
},
resolve: (root, args, { loaders }) => loaders.account.load(args),
},
Upvotes: 6
Views: 3721
Reputation: 29172
You need escape double-qoutes inside query-string:
{
accounts (
filter: "{\"fieldName\":\"id\",\"fieldValues\":[\"123\"],\"filterType\":\"in\"}"
){ id }
}
Upvotes: 2