Skip to content

Commit 176d479

Browse files
committed
Deprecate fragments with variables and reflect that in naming
Replicates graphql/graphql-js@920b45a
1 parent a6bd2a0 commit 176d479

File tree

7 files changed

+25
-27
lines changed

7 files changed

+25
-27
lines changed

src/graphql/language/parser.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
def parse(
7272
source: SourceType,
7373
no_location: bool = False,
74-
experimental_fragment_variables: bool = False,
74+
allow_legacy_fragment_variables: bool = False,
7575
) -> DocumentNode:
7676
"""Given a GraphQL source, parse it into a Document.
7777
@@ -81,9 +81,9 @@ def parse(
8181
they correspond to. The ``no_location`` option disables that behavior for
8282
performance or testing.
8383
84-
Experimental features:
84+
Legacy feature (will be removed in v3.3):
8585
86-
If ``experimental_fragment_variables`` is set to ``True``, the parser will
86+
If ``allow_legacy_fragment_variables`` is set to ``True``, the parser will
8787
understand and parse variable definitions contained in a fragment definition.
8888
They'll be represented in the
8989
:attr:`~graphql.language.FragmentDefinitionNode.variable_definitions` field
@@ -98,15 +98,15 @@ def parse(
9898
parser = Parser(
9999
source,
100100
no_location=no_location,
101-
experimental_fragment_variables=experimental_fragment_variables,
101+
allow_legacy_fragment_variables=allow_legacy_fragment_variables,
102102
)
103103
return parser.parse_document()
104104

105105

106106
def parse_value(
107107
source: SourceType,
108108
no_location: bool = False,
109-
experimental_fragment_variables: bool = False,
109+
allow_legacy_fragment_variables: bool = False,
110110
) -> ValueNode:
111111
"""Parse the AST for a given string containing a GraphQL value.
112112
@@ -121,7 +121,7 @@ def parse_value(
121121
parser = Parser(
122122
source,
123123
no_location=no_location,
124-
experimental_fragment_variables=experimental_fragment_variables,
124+
allow_legacy_fragment_variables=allow_legacy_fragment_variables,
125125
)
126126
parser.expect_token(TokenKind.SOF)
127127
value = parser.parse_value_literal(False)
@@ -132,7 +132,7 @@ def parse_value(
132132
def parse_type(
133133
source: SourceType,
134134
no_location: bool = False,
135-
experimental_fragment_variables: bool = False,
135+
allow_legacy_fragment_variables: bool = False,
136136
) -> TypeNode:
137137
"""Parse the AST for a given string containing a GraphQL Type.
138138
@@ -147,7 +147,7 @@ def parse_type(
147147
parser = Parser(
148148
source,
149149
no_location=no_location,
150-
experimental_fragment_variables=experimental_fragment_variables,
150+
allow_legacy_fragment_variables=allow_legacy_fragment_variables,
151151
)
152152
parser.expect_token(TokenKind.SOF)
153153
type_ = parser.parse_type_reference()
@@ -169,21 +169,21 @@ class Parser:
169169

170170
_lexer: Lexer
171171
_no_Location: bool
172-
_experimental_fragment_variables: bool
172+
_allow_legacy_fragment_variables: bool
173173

174174
def __init__(
175175
self,
176176
source: SourceType,
177177
no_location: bool = False,
178-
experimental_fragment_variables: bool = False,
178+
allow_legacy_fragment_variables: bool = False,
179179
):
180180
source = (
181181
cast(Source, source) if is_source(source) else Source(cast(str, source))
182182
)
183183

184184
self._lexer = Lexer(source)
185185
self._no_location = no_location
186-
self._experimental_fragment_variables = experimental_fragment_variables
186+
self._allow_legacy_fragment_variables = allow_legacy_fragment_variables
187187

188188
def parse_name(self) -> NameNode:
189189
"""Convert a name lex token into a name parse node."""
@@ -389,9 +389,9 @@ def parse_fragment_definition(self) -> FragmentDefinitionNode:
389389
"""FragmentDefinition"""
390390
start = self._lexer.token
391391
self.expect_keyword("fragment")
392-
# Experimental support for defining variables within fragments changes
392+
# Legacy support for defining variables within fragments changes
393393
# the grammar of FragmentDefinition
394-
if self._experimental_fragment_variables:
394+
if self._allow_legacy_fragment_variables:
395395
return FragmentDefinitionNode(
396396
name=self.parse_fragment_name(),
397397
variable_definitions=self.parse_variable_definitions(),

src/graphql/language/printer.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,7 @@ def leave_inline_fragment(node: PrintedNode, *_args: Any) -> str:
134134

135135
@staticmethod
136136
def leave_fragment_definition(node: PrintedNode, *_args: Any) -> str:
137-
# Note: fragment variable definitions are experimental and may be changed or
138-
# removed in the future.
137+
# Note: fragment variable definitions are deprecated and will be removed in v3.3
139138
return (
140139
f"fragment {node.name}"
141140
f"{wrap('(', join(node.variable_definitions, ', '), ')')}"

src/graphql/language/visitor.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ class VisitorActionEnum(Enum):
6969
"fragment_spread": ("name", "directives"),
7070
"inline_fragment": ("type_condition", "directives", "selection_set"),
7171
"fragment_definition": (
72-
# Note: fragment variable definitions are experimental and may be changed or
73-
# removed in the future.
72+
# Note: fragment variable definitions are deprecated and will be removed in v3.3
7473
"name",
7574
"variable_definitions",
7675
"type_condition",

src/graphql/utilities/build_ast_schema.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,14 @@ def build_schema(
8080
assume_valid: bool = False,
8181
assume_valid_sdl: bool = False,
8282
no_location: bool = False,
83-
experimental_fragment_variables: bool = False,
83+
allow_legacy_fragment_variables: bool = False,
8484
) -> GraphQLSchema:
8585
"""Build a GraphQLSchema directly from a source document."""
8686
return build_ast_schema(
8787
parse(
8888
source,
8989
no_location=no_location,
90-
experimental_fragment_variables=experimental_fragment_variables,
90+
allow_legacy_fragment_variables=allow_legacy_fragment_variables,
9191
),
9292
assume_valid=assume_valid,
9393
assume_valid_sdl=assume_valid_sdl,

tests/language/test_parser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,9 +351,9 @@ def allows_parsing_without_source_location_information():
351351
result = parse("{ id }", no_location=True)
352352
assert result.loc is None
353353

354-
def experimental_allows_parsing_fragment_defined_variables():
354+
def legacy_allows_parsing_fragment_defined_variables():
355355
document = "fragment a($v: Boolean = false) on t { f(v: $v) }"
356-
parse(document, experimental_fragment_variables=True)
356+
parse(document, allow_legacy_fragment_variables=True)
357357
with raises(GraphQLSyntaxError):
358358
parse(document)
359359

tests/language/test_printer.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,10 @@ def puts_arguments_on_multiple_lines_if_line_has_more_than_80_chars():
114114
"""
115115
)
116116

117-
def experimental_prints_fragment_with_variable_directives():
117+
def legacy_prints_fragment_with_variable_directives():
118118
query_ast_with_variable_directive = parse(
119119
"fragment Foo($foo: TestType @test) on TestType @testDirective { id }",
120-
experimental_fragment_variables=True,
120+
allow_legacy_fragment_variables=True,
121121
)
122122
assert print_ast(query_ast_with_variable_directive) == dedent(
123123
"""
@@ -127,13 +127,13 @@ def experimental_prints_fragment_with_variable_directives():
127127
"""
128128
)
129129

130-
def experimental_correctly_prints_fragment_defined_variables():
130+
def legacy_correctly_prints_fragment_defined_variables():
131131
source = """
132132
fragment Foo($a: ComplexType, $b: Boolean = false) on TestType {
133133
id
134134
}
135135
"""
136-
fragment_with_variable = parse(source, experimental_fragment_variables=True)
136+
fragment_with_variable = parse(source, allow_legacy_fragment_variables=True)
137137
assert print_ast(fragment_with_variable) == dedent(source)
138138

139139
# noinspection PyShadowingNames

tests/language/test_visitor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -540,11 +540,11 @@ def leave_selection_set(*args):
540540
["leave", "selection_set", None],
541541
]
542542

543-
def experimental_visits_variables_defined_in_fragments():
543+
def legacy_visits_variables_defined_in_fragments():
544544
ast = parse(
545545
"fragment a($v: Boolean = false) on t { f }",
546546
no_location=True,
547-
experimental_fragment_variables=True,
547+
allow_legacy_fragment_variables=True,
548548
)
549549
visited = []
550550

0 commit comments

Comments
 (0)