Skip to content

Commit b9423b7

Browse files
committed
Deprecate FrozenDict/List, use tuples as node lists
These utility classes were a bit awkward and e.g. caused problems with pickle since a list object is assumed to be appendable (#112). Instead of FrozenLists, we now use homogeneous tuples to guarantee that node lists and other collections are immutable. We also use the Collection and Mapping types to indicate immutability. Ordinary tuples are more lightweight and pythonic than FrozenLists. We also exclude the links when pickling Tokens in order to make pickling GraphQL schemas (which contain the tokens) less expensive.
1 parent 9a2ee03 commit b9423b7

32 files changed

+503
-538
lines changed

docs/modules/pyutils.rst

-8
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,6 @@ PyUtils
2525
:no-members:
2626
:no-inherited-members:
2727
:no-special-members:
28-
.. autoclass:: FrozenList
29-
:no-members:
30-
:no-inherited-members:
31-
:no-special-members:
32-
.. autoclass:: FrozenDict
33-
:no-members:
34-
:no-inherited-members:
35-
:no-special-members:
3628
.. autoclass:: Path
3729
.. autofunction:: print_path_list
3830
.. autoclass:: SimplePubSub

docs/modules/type.rst

+7-4
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,9 @@ Definitions
122122
.. autoclass:: GraphQLSkipDirective
123123
.. autoclass:: GraphQLDeprecatedDirective
124124

125-
.. autodata:: specified_directives
125+
.. data:: specified_directives
126+
127+
A tuple with all directives from the GraphQL specification
126128

127129
.. data:: DEFAULT_DEPRECATION_REASON
128130
:annotation: = 'No longer supported'
@@ -146,7 +148,9 @@ Definitions
146148
.. autoclass:: TypeNameMetaFieldDef
147149
.. autoclass:: SchemaMetaFieldDef
148150

149-
.. autodata:: introspection_types
151+
.. data:: introspection_types
152+
153+
This is a mapping containing all introspection types with their names as keys
150154

151155

152156
Scalars
@@ -166,8 +170,7 @@ Definitions
166170
.. autoclass:: GraphQLInt
167171
.. autoclass:: GraphQLString
168172

169-
The list of all specified directives is available as
170-
:data:`specified_directives`.
173+
A tuple with all specified directives is available as :data:`specified_directives`.
171174

172175

173176
Schema

docs/modules/validation.rst

+3-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ Rules
2929
.. module:: graphql.validation.rules
3030
.. currentmodule:: graphql.validation
3131

32-
.. autodata:: specified_rules
33-
:annotation: = FrozenList([...])
32+
.. data:: specified_rules
33+
34+
A tuple with all validation rules defined by the GraphQL specification
3435

3536
**Spec Section: "Executable Definitions"**
3637

src/graphql/execution/execute.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
is_awaitable as default_is_awaitable,
3535
is_iterable,
3636
AwaitableOrValue,
37-
FrozenList,
3837
Path,
3938
Undefined,
4039
)
@@ -285,7 +284,7 @@ def build(
285284

286285
coerced_variable_values = get_variable_values(
287286
schema,
288-
operation.variable_definitions or FrozenList(),
287+
operation.variable_definitions or (),
289288
raw_variable_values or {},
290289
max_errors=50,
291290
)

src/graphql/execution/values.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, Callable, Dict, List, Optional, Union, cast
1+
from typing import Any, Callable, Collection, Dict, List, Optional, Union, cast
22

33
from ..error import GraphQLError
44
from ..language import (
@@ -17,7 +17,7 @@
1717
VariableNode,
1818
print_ast,
1919
)
20-
from ..pyutils import inspect, print_path_list, FrozenList, Undefined
20+
from ..pyutils import inspect, print_path_list, Undefined
2121
from ..type import (
2222
GraphQLDirective,
2323
GraphQLField,
@@ -38,7 +38,7 @@
3838

3939
def get_variable_values(
4040
schema: GraphQLSchema,
41-
var_def_nodes: FrozenList[VariableDefinitionNode],
41+
var_def_nodes: Collection[VariableDefinitionNode],
4242
inputs: Dict[str, Any],
4343
max_errors: Optional[int] = None,
4444
) -> CoercedVariableValues:
@@ -72,7 +72,7 @@ def on_error(error: GraphQLError) -> None:
7272

7373
def coerce_variable_values(
7474
schema: GraphQLSchema,
75-
var_def_nodes: FrozenList[VariableDefinitionNode],
75+
var_def_nodes: Collection[VariableDefinitionNode],
7676
inputs: Dict[str, Any],
7777
on_error: Callable[[GraphQLError], None],
7878
) -> Dict[str, Any]:

0 commit comments

Comments
 (0)