Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for variable definitions in dsl #210

Merged
merged 16 commits into from
Jun 5, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add type hint to DSLVariable and DSLVariableDefinitions
wallee94 committed Jun 3, 2021
commit 4c3b39790e6a7c4b79e92b7ac8b2c5d9e326ed7a
15 changes: 12 additions & 3 deletions gql/dsl.py
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@
GraphQLNonNull,
GraphQLObjectType,
GraphQLSchema,
GraphQLWrappingType,
ListTypeNode,
ListValueNode,
NamedTypeNode,
@@ -27,10 +28,12 @@
OperationDefinitionNode,
OperationType,
SelectionSetNode,
TypeNode,
Undefined,
ValueNode,
VariableDefinitionNode,
VariableNode,
assert_named_type,
is_input_object_type,
is_list_type,
is_non_null_type,
@@ -287,20 +290,26 @@ class DSLVariable:
in the `args` method.
"""

def __init__(self, name):
def __init__(self, name: str):
self.type = None
self.name = name
self.ast_variable = VariableNode(name=NameNode(value=self.name))

def to_ast_type(self, type_):
def to_ast_type(
self, type_: Union[GraphQLWrappingType, GraphQLNamedType]
) -> TypeNode:
if is_wrapping_type(type_):
if isinstance(type_, GraphQLList):
return ListTypeNode(type=self.to_ast_type(type_.of_type))
elif isinstance(type_, GraphQLNonNull):
return NonNullTypeNode(type=self.to_ast_type(type_.of_type))

type_ = assert_named_type(type_)
return NamedTypeNode(name=NameNode(value=type_.name))

def set_type(self, type_) -> "DSLVariable":
def set_type(
self, type_: Union[GraphQLWrappingType, GraphQLNamedType]
) -> "DSLVariable":
self.type = self.to_ast_type(type_)
return self