Skip to content

fix(graphql): reject malformed SDK query envelopes - #13605

Merged
HarshMN2345 merged 6 commits into
mainfrom
codex/sentry-graphql-batch
Sep 11, 2026
Merged

HarshMN2345 merged 6 commits into
mainfrom
codex/sentry-graphql-batch

Conversation

@HarshMN2345

@HarshMN2345 HarshMN2345 commented Sep 10, 2026 •

Copy link
Copy Markdown
Member

What does this PR do?

Return HTTP 400 instead of 500 when a GraphQL SDK request (x-sdk-graphql: true) contains an invalid query envelope. Both POST endpoints validate the unwrapped value before execution:

  • a string, number or boolean query returns general_argument_invalid, with a message showing the accepted shape {"query": "...", "variables": {}}
  • a missing, null, {} or [] query returns the existing graphql_no_query
  • valid query objects and batches keep their current behavior

Fixes CLOUD-3QWQ.

The string envelope comes from the JS SDKs: the documented graphql.query({ query, variables }) call is read as the SDK's params-object overload and sent as {"query":"<document>"} without its variables. appwrite/sdk-generator#1897 fixes the SDKs. The server keeps rejecting the flat body instead of running it, because the variables are already gone and nullable ones would silently run as null.

Test Plan

  • Reproduced HTTP 500 on /v1/graphql and /v1/graphql/mutation for string, {} and missing envelopes on main; each returns 400 on this branch.
  • test tests/e2e/Services/GraphQL/ContentTypeTest.php tests/e2e/Services/GraphQL/BatchTest.php: 39 tests, 182 assertions passed.
  • Pint passes for the changed files.

@greptile-apps

greptile-apps Bot commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

The PR appears safe to merge; no actionable correctness, security, or repository-rule violations remain.

Summary

  • Normalizes missing, null, and empty-object envelopes so they retain the existing no-query response.
  • Rejects scalar envelopes with an HTTP 400 argument error on both GraphQL POST routes.
  • Adds route-shared coverage for valid single and batch requests and malformed envelope variants.

Reviews (5) · Last reviewed commit: "Merge branch 'main' into codex/sentry-gr..."

@github-actions

github-actions Bot commented Sep 10, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → codex/sentry-graphql-batch (after).

Metric Before After Change
🚀 Requests/sec 251.32 249.43 ⚪ -0.8%
⏱️ Latency P50 69.96 ms 69.88 ms ⚪ -0.1%
⏱️ Latency P95 161.64 ms 164.03 ms ⚪ +1.5%
Per-scenario breakdown & investigation details

Metrics below reflect the current branch (after). Δ P95 compares against the base.

Scenario P50 (ms) P95 (ms) Requests RPS Δ P95 (ms)
API total 69.88 164.03 15,789 249.43 +2.39
Account 135.99 246.05 831 13.78 -3.31
TablesDB 67.57 125.84 8,587 138.5 +2.77
Storage 63.34 142.13 4,155 68.83 -0.71
Functions 101.03 200.98 2,216 37.33 +7.78

Top API waits (after)

API request Max wait (ms)
functions.variables.update 354.38
account.name.update 352.6
tablesdb.rows.delete 341.84
functions.delete 334.1
tablesdb.rows.create 329.5

HarshMN2345 and others added 3 commits September 10, 2026 18:21
`execute()` keeps its `array` signature; the two POST endpoints reject a
non-array `query` envelope before execution, which is the only place a
non-array can arise since `getParams()` always returns an array.

Trim the new assertions to the behaviour each test is named for.
A string or scalar SDK `query` envelope now points the caller at
`{"query": "...", "variables": {}}`, the object shape the endpoint accepts.
@HarshMN2345
HarshMN2345 merged commit 30e8338 into main Sep 11, 2026
45 of 46 checks passed
@ChiragAgg5k ChiragAgg5k mentioned this pull request Sep 11, 2026
2 of 4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants