Intermittent `expected ')' following parenthesized expression` error affecting 10-30% of GQL calls to Sanity

7 replies
Last updated: Jun 8, 2023
πŸ‘‹ Hey folks! Wanted to echo this issue , which for us is affecting roughly 10-30% of all GQL calls to Sanity. I've tested sending the same payload over and over, with the same intermittent results - so I can verify it's not a difference in the data we're sending or how we're sending it. This points to it being an issue on Sanitys side, where occasionally we'll get
expected ')' following parenthesized expression
as a response with a
400
code. While we aggressively cache, this has the potential for breaking our frontend which heavily relies on Sanity.
I do see that Sanitys status page is all green, but this seems like a fairly serious issue if it is on their side like I suspect.
πŸ€”
AI Update

I understand this is frustrating - intermittent failures with identical payloads are definitely concerning. However, before assuming this is a Sanity infrastructure issue, let's work through some troubleshooting steps since the "expected ')' following parenthesized expression" error typically indicates a GraphQL syntax problem.

What this error usually means

This error message is a GraphQL syntax error - it means the GraphQL parser encountered malformed syntax, typically an unclosed parenthesis or incorrect query structure. While you mention sending "the same payload over and over," there could be factors causing variation in what actually reaches Sanity's servers.

Troubleshooting steps

Inspect the actual requests being sent - Even if your code appears to send identical payloads, check:

  • Are variables being interpolated correctly every time?
  • Could any dynamic content (field names, arguments, variables) occasionally contain special characters that break syntax?
  • Are there any middleware, proxies, or transformations that might occasionally modify requests?
  • Log the raw request body immediately before sending to verify it's truly identical

Check for variable serialization issues - GraphQL variables that aren't properly serialized can cause intermittent syntax errors:

// Bad - might create syntax issues
const variables = { filter: `name == "${userInput}"` }

// Good - properly structured
const variables = { filter: { name: { eq: userInput } } }

Examine your GraphQL query structure - Common syntax issues include:

  • Mismatched parentheses in field arguments
  • Missing or extra commas in selection sets
  • Improperly nested fragments
  • Variable definitions that don't match usage

Test with a minimal query - Strip your query down to the simplest possible version and gradually add complexity to isolate where the issue occurs.

Why intermittent failures happen

Even with "identical" payloads, intermittent failures can occur due to:

  • Client-side state changes affecting query generation
  • Race conditions in your application code constructing queries
  • Network layer issues corrupting request bodies (rare but possible)
  • Character encoding problems with certain content

Next steps

Contact Sanity support with specific details:

  • Your exact GraphQL query (the full query string, not just the structure)
  • The complete error response including any error extensions
  • Your project ID and timestamps of failures
  • Request/response headers
  • Whether you're using the GraphQL API directly or through a client library

Provide them with the raw request body from both successful and failed attempts if you can capture them.

Consider using GROQ temporarily - If this is blocking production, Sanity's native GROQ query language provides an alternative way to query the Content Lake. Note that GROQ and GraphQL are different query interfaces with different syntax and capabilities, so this would require rewriting queries rather than being a drop-in replacement.

Implement retry logic - While investigating, add retry logic for 400 errors as a defensive measure, though this treats the symptom rather than the cause.

The status page showing green doesn't necessarily mean there isn't an issue, but the specific error message you're seeing strongly suggests a query syntax problem rather than general infrastructure issues. Sanity's support team will have access to server-side logs that can definitively show whether the queries arriving at their servers are malformed or if there's something else happening.

Minimum reproducable query I could generate is:
query {
  allDocument(
    where: {
    	_: { is_draft: true }
    } 
  ){_id}
}
It seems to now happen 100% of the time when we set is_draft to true.
Thanks for reporting. We’re invesstigating!
user B
are you able to check this again now for me?
Looks like it works now! πŸŽ‰πŸŽ‰
Woohoo! Thank you for confirming
Thanks
user Y
and
user M
!
Thanks again for flagging!

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Was this answer helpful?