Skip to content

Commit 9852529

Browse files
committed
Fixed argument output name. Fixed #490
1 parent c41b183 commit 9852529

File tree

3 files changed

+71
-52
lines changed

3 files changed

+71
-52
lines changed

graphene/tests/issues/test_490.py

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# https://github.com/graphql-python/graphene/issues/313
2+
3+
import graphene
4+
from graphene import resolve_only_args
5+
6+
7+
class Query(graphene.ObjectType):
8+
some_field = graphene.String(from_=graphene.String(name="from"))
9+
10+
def resolve_some_field(_, args, context, infos):
11+
return args.get("from_")
12+
13+
14+
def test_issue():
15+
query_string = '''
16+
query myQuery {
17+
someField(from: "Oh")
18+
}
19+
'''
20+
21+
schema = graphene.Schema(query=Query)
22+
result = schema.execute(query_string)
23+
24+
assert not result.errors
25+
assert result.data['someField'] == 'Oh'

graphene/types/tests/test_datetime.py

+16-22
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ class Query(ObjectType):
1111
time = Time(_at=Time(name='at'))
1212

1313
def resolve_datetime(self, args, context, info):
14-
_in = args.get('in')
14+
_in = args.get('_in')
1515
return _in
1616

1717
def resolve_time(self, args, context, info):
18-
return args.get('at')
18+
return args.get('_at')
19+
1920

2021
schema = Schema(query=Query)
2122

@@ -24,48 +25,41 @@ def test_datetime_query():
2425
now = datetime.datetime.now().replace(tzinfo=pytz.utc)
2526
isoformat = now.isoformat()
2627

27-
result = schema.execute('''{ datetime(in: "%s") }'''%isoformat)
28+
result = schema.execute('''{ datetime(in: "%s") }''' % isoformat)
2829
assert not result.errors
29-
assert result.data == {
30-
'datetime': isoformat
31-
}
30+
assert result.data == {'datetime': isoformat}
3231

3332

3433
def test_time_query():
3534
now = datetime.datetime.now().replace(tzinfo=pytz.utc)
36-
time = datetime.time(now.hour, now.minute, now.second, now.microsecond, now.tzinfo)
35+
time = datetime.time(now.hour, now.minute, now.second, now.microsecond,
36+
now.tzinfo)
3737
isoformat = time.isoformat()
3838

39-
result = schema.execute('''{ time(at: "%s") }'''%isoformat)
39+
result = schema.execute('''{ time(at: "%s") }''' % isoformat)
4040
assert not result.errors
41-
assert result.data == {
42-
'time': isoformat
43-
}
41+
assert result.data == {'time': isoformat}
42+
4443

4544
def test_datetime_query_variable():
4645
now = datetime.datetime.now().replace(tzinfo=pytz.utc)
4746
isoformat = now.isoformat()
4847

4948
result = schema.execute(
5049
'''query Test($date: DateTime){ datetime(in: $date) }''',
51-
variable_values={'date': isoformat}
52-
)
50+
variable_values={'date': isoformat})
5351
assert not result.errors
54-
assert result.data == {
55-
'datetime': isoformat
56-
}
52+
assert result.data == {'datetime': isoformat}
5753

5854

5955
def test_time_query_variable():
6056
now = datetime.datetime.now().replace(tzinfo=pytz.utc)
61-
time = datetime.time(now.hour, now.minute, now.second, now.microsecond, now.tzinfo)
57+
time = datetime.time(now.hour, now.minute, now.second, now.microsecond,
58+
now.tzinfo)
6259
isoformat = time.isoformat()
6360

6461
result = schema.execute(
6562
'''query Test($time: Time){ time(at: $time) }''',
66-
variable_values={'time': isoformat}
67-
)
63+
variable_values={'time': isoformat})
6864
assert not result.errors
69-
assert result.data == {
70-
'time': isoformat
71-
}
65+
assert result.data == {'time': isoformat}

graphene/types/typemap.py

+30-30
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@
3131
def is_graphene_type(_type):
3232
if isinstance(_type, (List, NonNull)):
3333
return True
34-
if inspect.isclass(_type) and issubclass(_type, (ObjectType, InputObjectType, Scalar, Interface, Union, Enum)):
34+
if inspect.isclass(_type) and issubclass(_type,
35+
(ObjectType, InputObjectType,
36+
Scalar, Interface, Union, Enum)):
3537
return True
3638

3739

@@ -57,7 +59,6 @@ def is_type_of_from_possible_types(possible_types, root, context, info):
5759

5860

5961
class TypeMap(GraphQLTypeMap):
60-
6162
def __init__(self, types, auto_camelcase=True, schema=None):
6263
self.auto_camelcase = auto_camelcase
6364
self.schema = schema
@@ -96,7 +97,8 @@ def graphene_reducer(self, map, type):
9697
elif issubclass(type, Union):
9798
internal_type = self.construct_union(map, type)
9899
else:
99-
raise Exception("Expected Graphene type, but received: {}.".format(type))
100+
raise Exception(
101+
"Expected Graphene type, but received: {}.".format(type))
100102

101103
return GraphQLTypeMap.reducer(map, internal_type)
102104

@@ -117,11 +119,9 @@ def construct_scalar(self, map, type):
117119
graphene_type=type,
118120
name=type._meta.name,
119121
description=type._meta.description,
120-
121122
serialize=getattr(type, 'serialize', None),
122123
parse_value=getattr(type, 'parse_value', None),
123-
parse_literal=getattr(type, 'parse_literal', None),
124-
)
124+
parse_literal=getattr(type, 'parse_literal', None), )
125125

126126
def construct_enum(self, map, type):
127127
values = OrderedDict()
@@ -130,14 +130,12 @@ def construct_enum(self, map, type):
130130
name=name,
131131
value=value.value,
132132
description=getattr(value, 'description', None),
133-
deprecation_reason=getattr(value, 'deprecation_reason', None)
134-
)
133+
deprecation_reason=getattr(value, 'deprecation_reason', None))
135134
return GrapheneEnumType(
136135
graphene_type=type,
137136
values=values,
138137
name=type._meta.name,
139-
description=type._meta.description,
140-
)
138+
description=type._meta.description, )
141139

142140
def construct_objecttype(self, map, type):
143141
if type._meta.name in map:
@@ -158,7 +156,8 @@ def interfaces():
158156
return interfaces
159157

160158
if type._meta.possible_types:
161-
is_type_of = partial(is_type_of_from_possible_types, type._meta.possible_types)
159+
is_type_of = partial(is_type_of_from_possible_types,
160+
type._meta.possible_types)
162161
else:
163162
is_type_of = type.is_type_of
164163

@@ -168,8 +167,7 @@ def interfaces():
168167
description=type._meta.description,
169168
fields=partial(self.construct_fields_for_type, map, type),
170169
is_type_of=is_type_of,
171-
interfaces=interfaces
172-
)
170+
interfaces=interfaces)
173171

174172
def construct_interface(self, map, type):
175173
if type._meta.name in map:
@@ -182,27 +180,29 @@ def construct_interface(self, map, type):
182180

183181
_resolve_type = None
184182
if type.resolve_type:
185-
_resolve_type = partial(resolve_type, type.resolve_type, map, type._meta.name)
183+
_resolve_type = partial(resolve_type, type.resolve_type, map,
184+
type._meta.name)
186185
return GrapheneInterfaceType(
187186
graphene_type=type,
188187
name=type._meta.name,
189188
description=type._meta.description,
190189
fields=partial(self.construct_fields_for_type, map, type),
191-
resolve_type=_resolve_type,
192-
)
190+
resolve_type=_resolve_type, )
193191

194192
def construct_inputobjecttype(self, map, type):
195193
return GrapheneInputObjectType(
196194
graphene_type=type,
197195
name=type._meta.name,
198196
description=type._meta.description,
199-
fields=partial(self.construct_fields_for_type, map, type, is_input_type=True),
197+
fields=partial(
198+
self.construct_fields_for_type, map, type, is_input_type=True),
200199
)
201200

202201
def construct_union(self, map, type):
203202
_resolve_type = None
204203
if type.resolve_type:
205-
_resolve_type = partial(resolve_type, type.resolve_type, map, type._meta.name)
204+
_resolve_type = partial(resolve_type, type.resolve_type, map,
205+
type._meta.name)
206206

207207
def types():
208208
union_types = []
@@ -217,8 +217,7 @@ def types():
217217
graphene_type=type,
218218
name=type._meta.name,
219219
types=types,
220-
resolve_type=_resolve_type,
221-
)
220+
resolve_type=_resolve_type, )
222221

223222
def get_name(self, name):
224223
if self.auto_camelcase:
@@ -239,8 +238,7 @@ def construct_fields_for_type(self, map, type, is_input_type=False):
239238
field_type,
240239
default_value=field.default_value,
241240
out_name=field.name or name,
242-
description=field.description
243-
)
241+
description=field.description)
244242
else:
245243
args = OrderedDict()
246244
for arg_name, arg in field.args.items():
@@ -249,17 +247,17 @@ def construct_fields_for_type(self, map, type, is_input_type=False):
249247
processed_arg_name = arg.name or self.get_name(arg_name)
250248
args[processed_arg_name] = GraphQLArgument(
251249
arg_type,
252-
out_name=arg.name or arg_name,
250+
out_name=arg_name,
253251
description=arg.description,
254-
default_value=arg.default_value
255-
)
252+
default_value=arg.default_value)
256253
_field = GraphQLField(
257254
field_type,
258255
args=args,
259-
resolver=field.get_resolver(self.get_resolver_for_type(type, name, field.default_value)),
256+
resolver=field.get_resolver(
257+
self.get_resolver_for_type(type, name,
258+
field.default_value)),
260259
deprecation_reason=field.deprecation_reason,
261-
description=field.description
262-
)
260+
description=field.description)
263261
field_name = field.name or self.get_name(name)
264262
fields[field_name] = _field
265263
return fields
@@ -275,7 +273,8 @@ def get_resolver_for_type(self, type, name, default_value):
275273
for interface in type._meta.interfaces:
276274
if name not in interface._meta.fields:
277275
continue
278-
interface_resolver = getattr(interface, 'resolve_{}'.format(name), None)
276+
interface_resolver = getattr(interface,
277+
'resolve_{}'.format(name), None)
279278
if interface_resolver:
280279
break
281280
resolver = interface_resolver
@@ -284,7 +283,8 @@ def get_resolver_for_type(self, type, name, default_value):
284283
if resolver:
285284
return get_unbound_function(resolver)
286285

287-
default_resolver = type._meta.default_resolver or get_default_resolver()
286+
default_resolver = type._meta.default_resolver or get_default_resolver(
287+
)
288288
return partial(default_resolver, name, default_value)
289289

290290
def get_field_type(self, map, type):

0 commit comments

Comments
 (0)