Skip to content

Commit

Permalink
Add typed dicts for to_kwargs results (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cito committed Jan 13, 2022
1 parent 9ea9c37 commit 7894dc0
Show file tree
Hide file tree
Showing 14 changed files with 421 additions and 149 deletions.
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def on_missing_reference(app, env, node, contnode):
target = node.get('reftarget')
if not target:
return None
if target in ignore_references:
if target in ignore_references or target.endswith('Kwargs'):
return contnode
typ = node.get('reftype')
name = target.rsplit('.', 1)[-1]
Expand Down
2 changes: 2 additions & 0 deletions docs/modules/type.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ Un-modifiers

Definitions
^^^^^^^^^^^

.. autoclass:: GraphQLEnumType
.. autoclass:: GraphQLInputObjectType
.. autoclass:: GraphQLInterfaceType
Expand All @@ -74,6 +75,7 @@ Type Wrappers

Types
^^^^^

.. autoclass:: GraphQLAbstractType
.. autoclass:: GraphQLArgument
.. autoclass:: GraphQLArgumentMap
Expand Down
27 changes: 27 additions & 0 deletions src/graphql/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,20 @@
GraphQLResolveInfo,
ResponsePath,
GraphQLTypeResolver,
# Keyword args
GraphQLArgumentKwargs,
GraphQLDirectiveKwargs,
GraphQLEnumTypeKwargs,
GraphQLEnumValueKwargs,
GraphQLFieldKwargs,
GraphQLInputFieldKwargs,
GraphQLInputObjectTypeKwargs,
GraphQLInterfaceTypeKwargs,
GraphQLNamedTypeKwargs,
GraphQLObjectTypeKwargs,
GraphQLScalarTypeKwargs,
GraphQLSchemaKwargs,
GraphQLUnionTypeKwargs,
)

# Validate GraphQL queries.
Expand Down Expand Up @@ -545,6 +559,19 @@
"GraphQLResolveInfo",
"ResponsePath",
"GraphQLTypeResolver",
"GraphQLArgumentKwargs",
"GraphQLDirectiveKwargs",
"GraphQLEnumTypeKwargs",
"GraphQLEnumValueKwargs",
"GraphQLFieldKwargs",
"GraphQLInputFieldKwargs",
"GraphQLInputObjectTypeKwargs",
"GraphQLInterfaceTypeKwargs",
"GraphQLNamedTypeKwargs",
"GraphQLObjectTypeKwargs",
"GraphQLScalarTypeKwargs",
"GraphQLSchemaKwargs",
"GraphQLUnionTypeKwargs",
"Source",
"get_location",
"print_location",
Expand Down
2 changes: 2 additions & 0 deletions src/graphql/pyutils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from .frozen_error import FrozenError
from .frozen_list import FrozenList
from .frozen_dict import FrozenDict
from .merge_kwargs import merge_kwargs
from .path import Path
from .print_path_list import print_path_list
from .simple_pub_sub import SimplePubSub, SimplePubSubIterator
Expand All @@ -48,6 +49,7 @@
"is_awaitable",
"is_collection",
"is_iterable",
"merge_kwargs",
"natural_comparison_key",
"AwaitableOrValue",
"suggestion_list",
Expand Down
8 changes: 8 additions & 0 deletions src/graphql/pyutils/merge_kwargs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from typing import cast, Any, Dict, TypeVar

T = TypeVar("T")


def merge_kwargs(base_dict: T, **kwargs: Any) -> T:
"""Return arbitrary typed dictionary with some keyword args merged in."""
return cast(T, {**cast(Dict, base_dict), **kwargs})
29 changes: 29 additions & 0 deletions src/graphql/type/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
assert_schema,
# GraphQL Schema definition
GraphQLSchema,
# Keyword Args
GraphQLSchemaKwargs,
)

# Uphold the spec rules about naming.
Expand Down Expand Up @@ -95,6 +97,18 @@
GraphQLScalarSerializer,
GraphQLScalarValueParser,
GraphQLScalarLiteralParser,
# Keyword Args
GraphQLArgumentKwargs,
GraphQLEnumTypeKwargs,
GraphQLEnumValueKwargs,
GraphQLFieldKwargs,
GraphQLInputFieldKwargs,
GraphQLInputObjectTypeKwargs,
GraphQLInterfaceTypeKwargs,
GraphQLNamedTypeKwargs,
GraphQLObjectTypeKwargs,
GraphQLScalarTypeKwargs,
GraphQLUnionTypeKwargs,
# Resolvers
GraphQLFieldResolver,
GraphQLTypeResolver,
Expand All @@ -116,6 +130,8 @@
GraphQLSkipDirective,
GraphQLDeprecatedDirective,
GraphQLSpecifiedByDirective,
# Keyword Args
GraphQLDirectiveKwargs,
# Constant Deprecation Reason
DEFAULT_DEPRECATION_REASON,
)
Expand Down Expand Up @@ -155,6 +171,7 @@
"assert_name",
"assert_enum_value_name",
"GraphQLSchema",
"GraphQLSchemaKwargs",
"is_type",
"is_scalar_type",
"is_object_type",
Expand Down Expand Up @@ -228,6 +245,17 @@
"GraphQLScalarSerializer",
"GraphQLScalarValueParser",
"GraphQLScalarLiteralParser",
"GraphQLArgumentKwargs",
"GraphQLEnumTypeKwargs",
"GraphQLEnumValueKwargs",
"GraphQLFieldKwargs",
"GraphQLInputFieldKwargs",
"GraphQLInputObjectTypeKwargs",
"GraphQLInterfaceTypeKwargs",
"GraphQLNamedTypeKwargs",
"GraphQLObjectTypeKwargs",
"GraphQLScalarTypeKwargs",
"GraphQLUnionTypeKwargs",
"GraphQLFieldResolver",
"GraphQLTypeResolver",
"GraphQLIsTypeOfFn",
Expand All @@ -242,6 +270,7 @@
"GraphQLSkipDirective",
"GraphQLDeprecatedDirective",
"GraphQLSpecifiedByDirective",
"GraphQLDirectiveKwargs",
"DEFAULT_DEPRECATION_REASON",
"is_specified_scalar_type",
"specified_scalar_types",
Expand Down
Loading

0 comments on commit 7894dc0

Please sign in to comment.