Skip to content

Commit 5e598b6

Browse files
committed
Manually print defer and stream directives
1 parent 876d580 commit 5e598b6

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

strawberry/printer/printer.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,14 @@ def print_schema(schema: BaseSchema) -> str:
621621
if (printed_directive := print_directive(directive, schema=schema)) is not None
622622
]
623623

624+
if schema.config.enable_experimental_incremental_execution:
625+
directives.append(
626+
"directive @defer(if: Boolean, label: String) on FRAGMENT_SPREAD | INLINE_FRAGMENT"
627+
)
628+
directives.append(
629+
"directive @stream(if: Boolean, label: String, initialCount: Int = 0) on FIELD"
630+
)
631+
624632
def _name_getter(type_: Any) -> str:
625633
if hasattr(type_, "name"):
626634
return type_.name
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
from __future__ import annotations
2+
3+
import textwrap
4+
5+
import strawberry
6+
from strawberry.schema.config import StrawberryConfig
7+
from tests.conftest import skip_if_gql_32
8+
9+
pytestmark = skip_if_gql_32("GraphQL 3.3.0 is required for incremental execution")
10+
11+
12+
@strawberry.type
13+
class Query:
14+
hello: str
15+
16+
17+
def test_does_not_print_defer_and_stream_directives_when_experimental_execution_is_disabled():
18+
schema = strawberry.Schema(
19+
query=Query,
20+
config=StrawberryConfig(enable_experimental_incremental_execution=False),
21+
)
22+
23+
expected_type = """
24+
type Query {
25+
hello: String!
26+
}
27+
"""
28+
29+
assert str(schema) == textwrap.dedent(expected_type).strip()
30+
31+
32+
def test_prints_defer_and_stream_directives_when_experimental_execution_is_enabled():
33+
schema = strawberry.Schema(
34+
query=Query,
35+
config=StrawberryConfig(enable_experimental_incremental_execution=True),
36+
)
37+
38+
expected_type = """
39+
directive @defer(if: Boolean, label: String) on FRAGMENT_SPREAD | INLINE_FRAGMENT
40+
41+
directive @stream(if: Boolean, label: String, initialCount: Int = 0) on FIELD
42+
43+
type Query {
44+
hello: String!
45+
}
46+
"""
47+
48+
assert str(schema) == textwrap.dedent(expected_type).strip()

0 commit comments

Comments
 (0)