Skip to content

Commit 7894dc0

Browse files
committed
Add typed dicts for to_kwargs results (#99)
1 parent 9ea9c37 commit 7894dc0

14 files changed

+421
-149
lines changed

docs/conf.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def on_missing_reference(app, env, node, contnode):
154154
target = node.get('reftarget')
155155
if not target:
156156
return None
157-
if target in ignore_references:
157+
if target in ignore_references or target.endswith('Kwargs'):
158158
return contnode
159159
typ = node.get('reftype')
160160
name = target.rsplit('.', 1)[-1]

docs/modules/type.rst

+2
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ Un-modifiers
5959

6060
Definitions
6161
^^^^^^^^^^^
62+
6263
.. autoclass:: GraphQLEnumType
6364
.. autoclass:: GraphQLInputObjectType
6465
.. autoclass:: GraphQLInterfaceType
@@ -74,6 +75,7 @@ Type Wrappers
7475

7576
Types
7677
^^^^^
78+
7779
.. autoclass:: GraphQLAbstractType
7880
.. autoclass:: GraphQLArgument
7981
.. autoclass:: GraphQLArgumentMap

src/graphql/__init__.py

+27
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,20 @@
346346
GraphQLResolveInfo,
347347
ResponsePath,
348348
GraphQLTypeResolver,
349+
# Keyword args
350+
GraphQLArgumentKwargs,
351+
GraphQLDirectiveKwargs,
352+
GraphQLEnumTypeKwargs,
353+
GraphQLEnumValueKwargs,
354+
GraphQLFieldKwargs,
355+
GraphQLInputFieldKwargs,
356+
GraphQLInputObjectTypeKwargs,
357+
GraphQLInterfaceTypeKwargs,
358+
GraphQLNamedTypeKwargs,
359+
GraphQLObjectTypeKwargs,
360+
GraphQLScalarTypeKwargs,
361+
GraphQLSchemaKwargs,
362+
GraphQLUnionTypeKwargs,
349363
)
350364

351365
# Validate GraphQL queries.
@@ -545,6 +559,19 @@
545559
"GraphQLResolveInfo",
546560
"ResponsePath",
547561
"GraphQLTypeResolver",
562+
"GraphQLArgumentKwargs",
563+
"GraphQLDirectiveKwargs",
564+
"GraphQLEnumTypeKwargs",
565+
"GraphQLEnumValueKwargs",
566+
"GraphQLFieldKwargs",
567+
"GraphQLInputFieldKwargs",
568+
"GraphQLInputObjectTypeKwargs",
569+
"GraphQLInterfaceTypeKwargs",
570+
"GraphQLNamedTypeKwargs",
571+
"GraphQLObjectTypeKwargs",
572+
"GraphQLScalarTypeKwargs",
573+
"GraphQLSchemaKwargs",
574+
"GraphQLUnionTypeKwargs",
548575
"Source",
549576
"get_location",
550577
"print_location",

src/graphql/pyutils/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from .frozen_error import FrozenError
2929
from .frozen_list import FrozenList
3030
from .frozen_dict import FrozenDict
31+
from .merge_kwargs import merge_kwargs
3132
from .path import Path
3233
from .print_path_list import print_path_list
3334
from .simple_pub_sub import SimplePubSub, SimplePubSubIterator
@@ -48,6 +49,7 @@
4849
"is_awaitable",
4950
"is_collection",
5051
"is_iterable",
52+
"merge_kwargs",
5153
"natural_comparison_key",
5254
"AwaitableOrValue",
5355
"suggestion_list",

src/graphql/pyutils/merge_kwargs.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from typing import cast, Any, Dict, TypeVar
2+
3+
T = TypeVar("T")
4+
5+
6+
def merge_kwargs(base_dict: T, **kwargs: Any) -> T:
7+
"""Return arbitrary typed dictionary with some keyword args merged in."""
8+
return cast(T, {**cast(Dict, base_dict), **kwargs})

src/graphql/type/__init__.py

+29
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
assert_schema,
1313
# GraphQL Schema definition
1414
GraphQLSchema,
15+
# Keyword Args
16+
GraphQLSchemaKwargs,
1517
)
1618

1719
# Uphold the spec rules about naming.
@@ -95,6 +97,18 @@
9597
GraphQLScalarSerializer,
9698
GraphQLScalarValueParser,
9799
GraphQLScalarLiteralParser,
100+
# Keyword Args
101+
GraphQLArgumentKwargs,
102+
GraphQLEnumTypeKwargs,
103+
GraphQLEnumValueKwargs,
104+
GraphQLFieldKwargs,
105+
GraphQLInputFieldKwargs,
106+
GraphQLInputObjectTypeKwargs,
107+
GraphQLInterfaceTypeKwargs,
108+
GraphQLNamedTypeKwargs,
109+
GraphQLObjectTypeKwargs,
110+
GraphQLScalarTypeKwargs,
111+
GraphQLUnionTypeKwargs,
98112
# Resolvers
99113
GraphQLFieldResolver,
100114
GraphQLTypeResolver,
@@ -116,6 +130,8 @@
116130
GraphQLSkipDirective,
117131
GraphQLDeprecatedDirective,
118132
GraphQLSpecifiedByDirective,
133+
# Keyword Args
134+
GraphQLDirectiveKwargs,
119135
# Constant Deprecation Reason
120136
DEFAULT_DEPRECATION_REASON,
121137
)
@@ -155,6 +171,7 @@
155171
"assert_name",
156172
"assert_enum_value_name",
157173
"GraphQLSchema",
174+
"GraphQLSchemaKwargs",
158175
"is_type",
159176
"is_scalar_type",
160177
"is_object_type",
@@ -228,6 +245,17 @@
228245
"GraphQLScalarSerializer",
229246
"GraphQLScalarValueParser",
230247
"GraphQLScalarLiteralParser",
248+
"GraphQLArgumentKwargs",
249+
"GraphQLEnumTypeKwargs",
250+
"GraphQLEnumValueKwargs",
251+
"GraphQLFieldKwargs",
252+
"GraphQLInputFieldKwargs",
253+
"GraphQLInputObjectTypeKwargs",
254+
"GraphQLInterfaceTypeKwargs",
255+
"GraphQLNamedTypeKwargs",
256+
"GraphQLObjectTypeKwargs",
257+
"GraphQLScalarTypeKwargs",
258+
"GraphQLUnionTypeKwargs",
231259
"GraphQLFieldResolver",
232260
"GraphQLTypeResolver",
233261
"GraphQLIsTypeOfFn",
@@ -242,6 +270,7 @@
242270
"GraphQLSkipDirective",
243271
"GraphQLDeprecatedDirective",
244272
"GraphQLSpecifiedByDirective",
273+
"GraphQLDirectiveKwargs",
245274
"DEFAULT_DEPRECATION_REASON",
246275
"is_specified_scalar_type",
247276
"specified_scalar_types",

0 commit comments

Comments
 (0)