Skip to content

Commit

Permalink
fix(integrations): Handle None-value in GraphQL query
Browse files Browse the repository at this point in the history
Gracefully handle an empty GraphQL query.

Fixes getsentry#2715
  • Loading branch information
czyber committed Feb 18, 2024
1 parent 4d1b814 commit a2526cc
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
3 changes: 3 additions & 0 deletions sentry_sdk/integrations/strawberry.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ def on_operation(self):
operation_type = "query"
op = OP.GRAPHQL_QUERY

if self.execution_context.query is None:
self.execution_context.query = ""

if self.execution_context.query.strip().startswith("mutation"):
operation_type = "mutation"
op = OP.GRAPHQL_MUTATION
Expand Down
27 changes: 27 additions & 0 deletions tests/integrations/strawberry/test_strawberry_py3.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,3 +591,30 @@ def test_transaction_mutation(
"graphql.field_path": "Mutation.change",
"graphql.path": "change",
}


@parameterize_strawberry_test
def test_handle_none_query_gracefully(
request,
sentry_init,
capture_events,
client_factory,
async_execution,
framework_integrations,
):
sentry_init(
integrations=[
StrawberryIntegration(async_execution=async_execution),
]
+ framework_integrations,
)
events = capture_events()

schema = strawberry.Schema(Query)

client_factory = request.getfixturevalue(client_factory)
client = client_factory(schema)

client.post("/graphql", json={})

assert len(events) == 0, "expected no events to be sent to Sentry"

0 comments on commit a2526cc

Please sign in to comment.