mirror of
https://github.com/graphql-python/graphene.git
synced 2025-02-02 20:54:16 +03:00
Fixed argument output name. Fixed #490
This commit is contained in:
parent
c41b183fad
commit
985252920c
25
graphene/tests/issues/test_490.py
Normal file
25
graphene/tests/issues/test_490.py
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
# https://github.com/graphql-python/graphene/issues/313
|
||||||
|
|
||||||
|
import graphene
|
||||||
|
from graphene import resolve_only_args
|
||||||
|
|
||||||
|
|
||||||
|
class Query(graphene.ObjectType):
|
||||||
|
some_field = graphene.String(from_=graphene.String(name="from"))
|
||||||
|
|
||||||
|
def resolve_some_field(_, args, context, infos):
|
||||||
|
return args.get("from_")
|
||||||
|
|
||||||
|
|
||||||
|
def test_issue():
|
||||||
|
query_string = '''
|
||||||
|
query myQuery {
|
||||||
|
someField(from: "Oh")
|
||||||
|
}
|
||||||
|
'''
|
||||||
|
|
||||||
|
schema = graphene.Schema(query=Query)
|
||||||
|
result = schema.execute(query_string)
|
||||||
|
|
||||||
|
assert not result.errors
|
||||||
|
assert result.data['someField'] == 'Oh'
|
|
@ -11,11 +11,12 @@ class Query(ObjectType):
|
||||||
time = Time(_at=Time(name='at'))
|
time = Time(_at=Time(name='at'))
|
||||||
|
|
||||||
def resolve_datetime(self, args, context, info):
|
def resolve_datetime(self, args, context, info):
|
||||||
_in = args.get('in')
|
_in = args.get('_in')
|
||||||
return _in
|
return _in
|
||||||
|
|
||||||
def resolve_time(self, args, context, info):
|
def resolve_time(self, args, context, info):
|
||||||
return args.get('at')
|
return args.get('_at')
|
||||||
|
|
||||||
|
|
||||||
schema = Schema(query=Query)
|
schema = Schema(query=Query)
|
||||||
|
|
||||||
|
@ -24,23 +25,21 @@ def test_datetime_query():
|
||||||
now = datetime.datetime.now().replace(tzinfo=pytz.utc)
|
now = datetime.datetime.now().replace(tzinfo=pytz.utc)
|
||||||
isoformat = now.isoformat()
|
isoformat = now.isoformat()
|
||||||
|
|
||||||
result = schema.execute('''{ datetime(in: "%s") }'''%isoformat)
|
result = schema.execute('''{ datetime(in: "%s") }''' % isoformat)
|
||||||
assert not result.errors
|
assert not result.errors
|
||||||
assert result.data == {
|
assert result.data == {'datetime': isoformat}
|
||||||
'datetime': isoformat
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def test_time_query():
|
def test_time_query():
|
||||||
now = datetime.datetime.now().replace(tzinfo=pytz.utc)
|
now = datetime.datetime.now().replace(tzinfo=pytz.utc)
|
||||||
time = datetime.time(now.hour, now.minute, now.second, now.microsecond, now.tzinfo)
|
time = datetime.time(now.hour, now.minute, now.second, now.microsecond,
|
||||||
|
now.tzinfo)
|
||||||
isoformat = time.isoformat()
|
isoformat = time.isoformat()
|
||||||
|
|
||||||
result = schema.execute('''{ time(at: "%s") }'''%isoformat)
|
result = schema.execute('''{ time(at: "%s") }''' % isoformat)
|
||||||
assert not result.errors
|
assert not result.errors
|
||||||
assert result.data == {
|
assert result.data == {'time': isoformat}
|
||||||
'time': isoformat
|
|
||||||
}
|
|
||||||
|
|
||||||
def test_datetime_query_variable():
|
def test_datetime_query_variable():
|
||||||
now = datetime.datetime.now().replace(tzinfo=pytz.utc)
|
now = datetime.datetime.now().replace(tzinfo=pytz.utc)
|
||||||
|
@ -48,24 +47,19 @@ def test_datetime_query_variable():
|
||||||
|
|
||||||
result = schema.execute(
|
result = schema.execute(
|
||||||
'''query Test($date: DateTime){ datetime(in: $date) }''',
|
'''query Test($date: DateTime){ datetime(in: $date) }''',
|
||||||
variable_values={'date': isoformat}
|
variable_values={'date': isoformat})
|
||||||
)
|
|
||||||
assert not result.errors
|
assert not result.errors
|
||||||
assert result.data == {
|
assert result.data == {'datetime': isoformat}
|
||||||
'datetime': isoformat
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def test_time_query_variable():
|
def test_time_query_variable():
|
||||||
now = datetime.datetime.now().replace(tzinfo=pytz.utc)
|
now = datetime.datetime.now().replace(tzinfo=pytz.utc)
|
||||||
time = datetime.time(now.hour, now.minute, now.second, now.microsecond, now.tzinfo)
|
time = datetime.time(now.hour, now.minute, now.second, now.microsecond,
|
||||||
|
now.tzinfo)
|
||||||
isoformat = time.isoformat()
|
isoformat = time.isoformat()
|
||||||
|
|
||||||
result = schema.execute(
|
result = schema.execute(
|
||||||
'''query Test($time: Time){ time(at: $time) }''',
|
'''query Test($time: Time){ time(at: $time) }''',
|
||||||
variable_values={'time': isoformat}
|
variable_values={'time': isoformat})
|
||||||
)
|
|
||||||
assert not result.errors
|
assert not result.errors
|
||||||
assert result.data == {
|
assert result.data == {'time': isoformat}
|
||||||
'time': isoformat
|
|
||||||
}
|
|
||||||
|
|
|
@ -31,7 +31,9 @@ from .utils import get_field_as
|
||||||
def is_graphene_type(_type):
|
def is_graphene_type(_type):
|
||||||
if isinstance(_type, (List, NonNull)):
|
if isinstance(_type, (List, NonNull)):
|
||||||
return True
|
return True
|
||||||
if inspect.isclass(_type) and issubclass(_type, (ObjectType, InputObjectType, Scalar, Interface, Union, Enum)):
|
if inspect.isclass(_type) and issubclass(_type,
|
||||||
|
(ObjectType, InputObjectType,
|
||||||
|
Scalar, Interface, Union, Enum)):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
@ -57,7 +59,6 @@ def is_type_of_from_possible_types(possible_types, root, context, info):
|
||||||
|
|
||||||
|
|
||||||
class TypeMap(GraphQLTypeMap):
|
class TypeMap(GraphQLTypeMap):
|
||||||
|
|
||||||
def __init__(self, types, auto_camelcase=True, schema=None):
|
def __init__(self, types, auto_camelcase=True, schema=None):
|
||||||
self.auto_camelcase = auto_camelcase
|
self.auto_camelcase = auto_camelcase
|
||||||
self.schema = schema
|
self.schema = schema
|
||||||
|
@ -96,7 +97,8 @@ class TypeMap(GraphQLTypeMap):
|
||||||
elif issubclass(type, Union):
|
elif issubclass(type, Union):
|
||||||
internal_type = self.construct_union(map, type)
|
internal_type = self.construct_union(map, type)
|
||||||
else:
|
else:
|
||||||
raise Exception("Expected Graphene type, but received: {}.".format(type))
|
raise Exception(
|
||||||
|
"Expected Graphene type, but received: {}.".format(type))
|
||||||
|
|
||||||
return GraphQLTypeMap.reducer(map, internal_type)
|
return GraphQLTypeMap.reducer(map, internal_type)
|
||||||
|
|
||||||
|
@ -117,11 +119,9 @@ class TypeMap(GraphQLTypeMap):
|
||||||
graphene_type=type,
|
graphene_type=type,
|
||||||
name=type._meta.name,
|
name=type._meta.name,
|
||||||
description=type._meta.description,
|
description=type._meta.description,
|
||||||
|
|
||||||
serialize=getattr(type, 'serialize', None),
|
serialize=getattr(type, 'serialize', None),
|
||||||
parse_value=getattr(type, 'parse_value', None),
|
parse_value=getattr(type, 'parse_value', None),
|
||||||
parse_literal=getattr(type, 'parse_literal', None),
|
parse_literal=getattr(type, 'parse_literal', None), )
|
||||||
)
|
|
||||||
|
|
||||||
def construct_enum(self, map, type):
|
def construct_enum(self, map, type):
|
||||||
values = OrderedDict()
|
values = OrderedDict()
|
||||||
|
@ -130,14 +130,12 @@ class TypeMap(GraphQLTypeMap):
|
||||||
name=name,
|
name=name,
|
||||||
value=value.value,
|
value=value.value,
|
||||||
description=getattr(value, 'description', None),
|
description=getattr(value, 'description', None),
|
||||||
deprecation_reason=getattr(value, 'deprecation_reason', None)
|
deprecation_reason=getattr(value, 'deprecation_reason', None))
|
||||||
)
|
|
||||||
return GrapheneEnumType(
|
return GrapheneEnumType(
|
||||||
graphene_type=type,
|
graphene_type=type,
|
||||||
values=values,
|
values=values,
|
||||||
name=type._meta.name,
|
name=type._meta.name,
|
||||||
description=type._meta.description,
|
description=type._meta.description, )
|
||||||
)
|
|
||||||
|
|
||||||
def construct_objecttype(self, map, type):
|
def construct_objecttype(self, map, type):
|
||||||
if type._meta.name in map:
|
if type._meta.name in map:
|
||||||
|
@ -158,7 +156,8 @@ class TypeMap(GraphQLTypeMap):
|
||||||
return interfaces
|
return interfaces
|
||||||
|
|
||||||
if type._meta.possible_types:
|
if type._meta.possible_types:
|
||||||
is_type_of = partial(is_type_of_from_possible_types, type._meta.possible_types)
|
is_type_of = partial(is_type_of_from_possible_types,
|
||||||
|
type._meta.possible_types)
|
||||||
else:
|
else:
|
||||||
is_type_of = type.is_type_of
|
is_type_of = type.is_type_of
|
||||||
|
|
||||||
|
@ -168,8 +167,7 @@ class TypeMap(GraphQLTypeMap):
|
||||||
description=type._meta.description,
|
description=type._meta.description,
|
||||||
fields=partial(self.construct_fields_for_type, map, type),
|
fields=partial(self.construct_fields_for_type, map, type),
|
||||||
is_type_of=is_type_of,
|
is_type_of=is_type_of,
|
||||||
interfaces=interfaces
|
interfaces=interfaces)
|
||||||
)
|
|
||||||
|
|
||||||
def construct_interface(self, map, type):
|
def construct_interface(self, map, type):
|
||||||
if type._meta.name in map:
|
if type._meta.name in map:
|
||||||
|
@ -182,27 +180,29 @@ class TypeMap(GraphQLTypeMap):
|
||||||
|
|
||||||
_resolve_type = None
|
_resolve_type = None
|
||||||
if type.resolve_type:
|
if type.resolve_type:
|
||||||
_resolve_type = partial(resolve_type, type.resolve_type, map, type._meta.name)
|
_resolve_type = partial(resolve_type, type.resolve_type, map,
|
||||||
|
type._meta.name)
|
||||||
return GrapheneInterfaceType(
|
return GrapheneInterfaceType(
|
||||||
graphene_type=type,
|
graphene_type=type,
|
||||||
name=type._meta.name,
|
name=type._meta.name,
|
||||||
description=type._meta.description,
|
description=type._meta.description,
|
||||||
fields=partial(self.construct_fields_for_type, map, type),
|
fields=partial(self.construct_fields_for_type, map, type),
|
||||||
resolve_type=_resolve_type,
|
resolve_type=_resolve_type, )
|
||||||
)
|
|
||||||
|
|
||||||
def construct_inputobjecttype(self, map, type):
|
def construct_inputobjecttype(self, map, type):
|
||||||
return GrapheneInputObjectType(
|
return GrapheneInputObjectType(
|
||||||
graphene_type=type,
|
graphene_type=type,
|
||||||
name=type._meta.name,
|
name=type._meta.name,
|
||||||
description=type._meta.description,
|
description=type._meta.description,
|
||||||
fields=partial(self.construct_fields_for_type, map, type, is_input_type=True),
|
fields=partial(
|
||||||
|
self.construct_fields_for_type, map, type, is_input_type=True),
|
||||||
)
|
)
|
||||||
|
|
||||||
def construct_union(self, map, type):
|
def construct_union(self, map, type):
|
||||||
_resolve_type = None
|
_resolve_type = None
|
||||||
if type.resolve_type:
|
if type.resolve_type:
|
||||||
_resolve_type = partial(resolve_type, type.resolve_type, map, type._meta.name)
|
_resolve_type = partial(resolve_type, type.resolve_type, map,
|
||||||
|
type._meta.name)
|
||||||
|
|
||||||
def types():
|
def types():
|
||||||
union_types = []
|
union_types = []
|
||||||
|
@ -217,8 +217,7 @@ class TypeMap(GraphQLTypeMap):
|
||||||
graphene_type=type,
|
graphene_type=type,
|
||||||
name=type._meta.name,
|
name=type._meta.name,
|
||||||
types=types,
|
types=types,
|
||||||
resolve_type=_resolve_type,
|
resolve_type=_resolve_type, )
|
||||||
)
|
|
||||||
|
|
||||||
def get_name(self, name):
|
def get_name(self, name):
|
||||||
if self.auto_camelcase:
|
if self.auto_camelcase:
|
||||||
|
@ -239,8 +238,7 @@ class TypeMap(GraphQLTypeMap):
|
||||||
field_type,
|
field_type,
|
||||||
default_value=field.default_value,
|
default_value=field.default_value,
|
||||||
out_name=field.name or name,
|
out_name=field.name or name,
|
||||||
description=field.description
|
description=field.description)
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
args = OrderedDict()
|
args = OrderedDict()
|
||||||
for arg_name, arg in field.args.items():
|
for arg_name, arg in field.args.items():
|
||||||
|
@ -249,17 +247,17 @@ class TypeMap(GraphQLTypeMap):
|
||||||
processed_arg_name = arg.name or self.get_name(arg_name)
|
processed_arg_name = arg.name or self.get_name(arg_name)
|
||||||
args[processed_arg_name] = GraphQLArgument(
|
args[processed_arg_name] = GraphQLArgument(
|
||||||
arg_type,
|
arg_type,
|
||||||
out_name=arg.name or arg_name,
|
out_name=arg_name,
|
||||||
description=arg.description,
|
description=arg.description,
|
||||||
default_value=arg.default_value
|
default_value=arg.default_value)
|
||||||
)
|
|
||||||
_field = GraphQLField(
|
_field = GraphQLField(
|
||||||
field_type,
|
field_type,
|
||||||
args=args,
|
args=args,
|
||||||
resolver=field.get_resolver(self.get_resolver_for_type(type, name, field.default_value)),
|
resolver=field.get_resolver(
|
||||||
|
self.get_resolver_for_type(type, name,
|
||||||
|
field.default_value)),
|
||||||
deprecation_reason=field.deprecation_reason,
|
deprecation_reason=field.deprecation_reason,
|
||||||
description=field.description
|
description=field.description)
|
||||||
)
|
|
||||||
field_name = field.name or self.get_name(name)
|
field_name = field.name or self.get_name(name)
|
||||||
fields[field_name] = _field
|
fields[field_name] = _field
|
||||||
return fields
|
return fields
|
||||||
|
@ -275,7 +273,8 @@ class TypeMap(GraphQLTypeMap):
|
||||||
for interface in type._meta.interfaces:
|
for interface in type._meta.interfaces:
|
||||||
if name not in interface._meta.fields:
|
if name not in interface._meta.fields:
|
||||||
continue
|
continue
|
||||||
interface_resolver = getattr(interface, 'resolve_{}'.format(name), None)
|
interface_resolver = getattr(interface,
|
||||||
|
'resolve_{}'.format(name), None)
|
||||||
if interface_resolver:
|
if interface_resolver:
|
||||||
break
|
break
|
||||||
resolver = interface_resolver
|
resolver = interface_resolver
|
||||||
|
@ -284,7 +283,8 @@ class TypeMap(GraphQLTypeMap):
|
||||||
if resolver:
|
if resolver:
|
||||||
return get_unbound_function(resolver)
|
return get_unbound_function(resolver)
|
||||||
|
|
||||||
default_resolver = type._meta.default_resolver or get_default_resolver()
|
default_resolver = type._meta.default_resolver or get_default_resolver(
|
||||||
|
)
|
||||||
return partial(default_resolver, name, default_value)
|
return partial(default_resolver, name, default_value)
|
||||||
|
|
||||||
def get_field_type(self, map, type):
|
def get_field_type(self, map, type):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user