Skip to content

Commit a113ec8

Browse files
czyberantonpirker
andauthored
fix(integrations): Handle None-value in GraphQL query #2715 (#2762)
Gracefully handle an empty GraphQL query. Fixes #2715 Co-authored-by: Anton Pirker <anton.pirker@sentry.io>
1 parent b3cec58 commit a113ec8

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

sentry_sdk/integrations/strawberry.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ def on_operation(self):
145145
operation_type = "query"
146146
op = OP.GRAPHQL_QUERY
147147

148+
if self.execution_context.query is None:
149+
self.execution_context.query = ""
150+
148151
if self.execution_context.query.strip().startswith("mutation"):
149152
operation_type = "mutation"
150153
op = OP.GRAPHQL_MUTATION

tests/integrations/strawberry/test_strawberry_py3.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,3 +600,30 @@ def test_transaction_mutation(
600600
"graphql.path": "change",
601601
}
602602
)
603+
604+
605+
@parameterize_strawberry_test
606+
def test_handle_none_query_gracefully(
607+
request,
608+
sentry_init,
609+
capture_events,
610+
client_factory,
611+
async_execution,
612+
framework_integrations,
613+
):
614+
sentry_init(
615+
integrations=[
616+
StrawberryIntegration(async_execution=async_execution),
617+
]
618+
+ framework_integrations,
619+
)
620+
events = capture_events()
621+
622+
schema = strawberry.Schema(Query)
623+
624+
client_factory = request.getfixturevalue(client_factory)
625+
client = client_factory(schema)
626+
627+
client.post("/graphql", json={})
628+
629+
assert len(events) == 0, "expected no events to be sent to Sentry"

0 commit comments

Comments
 (0)