Skip to content

fix(strawberry): prepare for upstream extension removal #3649

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions sentry_sdk/integrations/strawberry.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,18 @@
from strawberry import Schema
from strawberry.extensions import SchemaExtension # type: ignore
from strawberry.extensions.tracing.utils import should_skip_tracing as strawberry_should_skip_tracing # type: ignore
from strawberry.http import async_base_view, sync_base_view # type: ignore
except ImportError:
raise DidNotEnable("strawberry-graphql is not installed")

try:
from strawberry.extensions.tracing import ( # type: ignore
SentryTracingExtension as StrawberrySentryAsyncExtension,
SentryTracingExtensionSync as StrawberrySentrySyncExtension,
)
from strawberry.http import async_base_view, sync_base_view # type: ignore
except ImportError:
raise DidNotEnable("strawberry-graphql is not installed")
StrawberrySentryAsyncExtension = None
StrawberrySentrySyncExtension = None

from typing import TYPE_CHECKING

Expand Down
21 changes: 17 additions & 4 deletions tests/integrations/strawberry/test_strawberry.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@
from fastapi import FastAPI
from fastapi.testclient import TestClient
from flask import Flask
from strawberry.extensions.tracing import (
SentryTracingExtension,
SentryTracingExtensionSync,
)
from strawberry.fastapi import GraphQLRouter
from strawberry.flask.views import GraphQLView

Expand All @@ -28,6 +24,15 @@
)
from tests.conftest import ApproxDict

try:
from strawberry.extensions.tracing import (
SentryTracingExtension,
SentryTracingExtensionSync,
)
except ImportError:
SentryTracingExtension = None
SentryTracingExtensionSync = None

parameterize_strawberry_test = pytest.mark.parametrize(
"client_factory,async_execution,framework_integrations",
(
Expand Down Expand Up @@ -143,6 +148,10 @@ def test_infer_execution_type_from_installed_packages_sync(sentry_init):
assert SentrySyncExtension in schema.extensions


@pytest.mark.skipif(
SentryTracingExtension is None,
reason="SentryTracingExtension no longer available in this Strawberry version",
)
def test_replace_existing_sentry_async_extension(sentry_init):
sentry_init(integrations=[StrawberryIntegration()])

Expand All @@ -152,6 +161,10 @@ def test_replace_existing_sentry_async_extension(sentry_init):
assert SentryAsyncExtension in schema.extensions


@pytest.mark.skipif(
SentryTracingExtensionSync is None,
reason="SentryTracingExtensionSync no longer available in this Strawberry version",
)
def test_replace_existing_sentry_sync_extension(sentry_init):
sentry_init(integrations=[StrawberryIntegration()])

Expand Down
Loading