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

For fix graphene#280 issue #82

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 4 additions & 3 deletions graphql/execution/values.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
GraphQLNonNull, GraphQLScalarType, is_input_type)
from ..utils.is_valid_value import is_valid_value
from ..utils.type_from_ast import type_from_ast
from ..utils.value_from_ast import value_from_ast
from ..utils.value_from_ast import value_from_ast, Undefined

__all__ = ['get_variable_values', 'get_argument_values']

Expand All @@ -29,6 +29,7 @@ def get_variable_values(schema, definition_asts, inputs):
return values



def get_argument_values(arg_defs, arg_asts, variables):
"""Prepares an object map of argument values given a list of argument
definitions and list of argument AST nodes."""
Expand All @@ -53,10 +54,10 @@ def get_argument_values(arg_defs, arg_asts, variables):
variables
)

if value is None:
if value == Undefined and arg_def.default_value is not None:
value = arg_def.default_value

if value is not None:
if value != Undefined:
result[name] = value

return result
Expand Down
24 changes: 14 additions & 10 deletions graphql/utils/value_from_ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from ..type import (GraphQLEnumType, GraphQLInputObjectType, GraphQLList,
GraphQLNonNull, GraphQLScalarType)

Undefined = object()
UndefinedList = [Undefined,]

def value_from_ast(value_ast, type, variables=None):
"""Given a type and a value AST node known to match this type, build a
Expand All @@ -12,12 +14,12 @@ def value_from_ast(value_ast, type, variables=None):
return value_from_ast(value_ast, type.of_type, variables)

if not value_ast:
return None
return Undefined

if isinstance(value_ast, ast.Variable):
variable_name = value_ast.name.value
if not variables or variable_name not in variables:
return None
return Undefined

# Note: we're not doing any checking that this variable is correct. We're assuming that this query
# has been validated and the variable usage here is of the correct type.
Expand All @@ -26,16 +28,17 @@ def value_from_ast(value_ast, type, variables=None):
if isinstance(type, GraphQLList):
item_type = type.of_type
if isinstance(value_ast, ast.ListValue):
return [value_from_ast(item_ast, item_type, variables)
for item_ast in value_ast.values]
result = [value_from_ast(item_ast, item_type, variables) for item_ast in value_ast.values]
return result if result != UndefinedList else Undefined

else:
return [value_from_ast(value_ast, item_type, variables)]
result = [value_from_ast(value_ast, item_type, variables)]
return result if result != UndefinedList else Undefined

if isinstance(type, GraphQLInputObjectType):
fields = type.get_fields()
if not isinstance(value_ast, ast.ObjectValue):
return None
return Undefined

field_asts = {}

Expand All @@ -45,23 +48,24 @@ def value_from_ast(value_ast, type, variables=None):
obj = {}
for field_name, field in fields.items():
field_ast = field_asts.get(field_name)
field_value_ast = None
field_value_ast = Undefined

if field_ast:
field_value_ast = field_ast.value

field_value = value_from_ast(
field_value_ast, field.type, variables
)
if field_value is None:
if field_value == Undefined and field.default_value is not None:
field_value = field.default_value

if field_value is not None:
if field_value != Undefined:
obj[field_name] = field_value

return obj

assert isinstance(type, (GraphQLScalarType, GraphQLEnumType)), \
'Must be input type'

return type.parse_literal(value_ast)
result = type.parse_literal(value_ast)
return result if result is not None else Undefined