I am trying to remove extra whitespaces and newline characters from my GraphQL query but the data between 2 double quotes in filter argument should remain intact.
Here's how the query is received on our fastly's CDN
# input
{"query":"query OpName {\n itemCollection (filter: { text: "aa aa aa", text2: "aa aa"}){\n group { slug\n\n\n\n text text2 } } }"}
# expected output
{"query":"query OpName { itemCollection (filter: { text: "aa aa aa", text2: "aa aa"}){ group { slug text text2 } } }"}
The objective is to
- Remove extra whitespaces from the query
- The whitespaces between 2 double quotes, should remain intact inside the graphql query (since the filter argument's value will be used to match records in our database)
We have tried the following:
\s+(?=(?:['|%22](?:\\['|%22]|[^'|%22])+['|%22]|[^'|%22])+$)
given at fastly docs\s+(?=([^"]*"[^"]*")*[^"]*$)
But it doesn't seem to work.