mirror of
https://github.com/graphql-python/graphene.git
synced 2025-02-17 03:50:44 +03:00
Updated input field names with out_name
This commit is contained in:
parent
208651a4c0
commit
6543f9272a
|
@ -1,8 +1,11 @@
|
||||||
|
import json
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
from graphql import execute, Source, parse
|
from graphql import execute, Source, parse
|
||||||
|
|
||||||
from ..objecttype import ObjectType
|
from ..objecttype import ObjectType
|
||||||
|
from ..inputfield import InputField
|
||||||
|
from ..inputobjecttype import InputObjectType
|
||||||
from ..scalars import String, Int
|
from ..scalars import String, Int
|
||||||
from ..schema import Schema
|
from ..schema import Schema
|
||||||
from ..structures import List
|
from ..structures import List
|
||||||
|
@ -33,6 +36,57 @@ def test_query_resolve_function():
|
||||||
assert executed.data == {'hello': 'World'}
|
assert executed.data == {'hello': 'World'}
|
||||||
|
|
||||||
|
|
||||||
|
def test_query_arguments():
|
||||||
|
class Query(ObjectType):
|
||||||
|
test = String(a_str=String(), a_int=Int())
|
||||||
|
|
||||||
|
def resolve_test(self, args, context, info):
|
||||||
|
return json.dumps([self, args], separators=(',', ':'))
|
||||||
|
|
||||||
|
test_schema = Schema(Query)
|
||||||
|
|
||||||
|
result = test_schema.execute('{ test }', None)
|
||||||
|
assert not result.errors
|
||||||
|
assert result.data == {'test': '[null,{}]'}
|
||||||
|
|
||||||
|
result = test_schema.execute('{ test(aStr: "String!") }', 'Source!')
|
||||||
|
assert not result.errors
|
||||||
|
assert result.data == {'test': '["Source!",{"a_str":"String!"}]'}
|
||||||
|
|
||||||
|
result = test_schema.execute('{ test(aInt: -123, aStr: "String!") }', 'Source!')
|
||||||
|
assert not result.errors
|
||||||
|
assert result.data in [
|
||||||
|
{'test': '["Source!",{"a_str":"String!","a_int":-123}]'},
|
||||||
|
{'test': '["Source!",{"a_int":-123,"a_str":"String!"}]'}
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def test_query_input_field():
|
||||||
|
class Input(InputObjectType):
|
||||||
|
a_field = String()
|
||||||
|
recursive_field = InputField(lambda: Input)
|
||||||
|
|
||||||
|
class Query(ObjectType):
|
||||||
|
test = String(a_input=Input())
|
||||||
|
|
||||||
|
def resolve_test(self, args, context, info):
|
||||||
|
return json.dumps([self, args], separators=(',', ':'))
|
||||||
|
|
||||||
|
test_schema = Schema(Query)
|
||||||
|
|
||||||
|
result = test_schema.execute('{ test }', None)
|
||||||
|
assert not result.errors
|
||||||
|
assert result.data == {'test': '[null,{}]'}
|
||||||
|
|
||||||
|
result = test_schema.execute('{ test(aInput: {aField: "String!"} ) }', 'Source!')
|
||||||
|
assert not result.errors
|
||||||
|
assert result.data == {'test': '["Source!",{"a_input":{"a_field":"String!"}}]'}
|
||||||
|
|
||||||
|
result = test_schema.execute('{ test(aInput: {recursiveField: {aField: "String!"}}) }', 'Source!')
|
||||||
|
assert not result.errors
|
||||||
|
assert result.data == {'test': '["Source!",{"a_input":{"recursive_field":{"a_field":"String!"}}}]'}
|
||||||
|
|
||||||
|
|
||||||
def test_query_middlewares():
|
def test_query_middlewares():
|
||||||
class Query(ObjectType):
|
class Query(ObjectType):
|
||||||
hello = String()
|
hello = String()
|
||||||
|
|
|
@ -67,7 +67,7 @@ def test_objecttype():
|
||||||
f = MyObjectType.resolve_foo
|
f = MyObjectType.resolve_foo
|
||||||
assert foo_field.resolver == getattr(f, '__func__', f)
|
assert foo_field.resolver == getattr(f, '__func__', f)
|
||||||
assert foo_field.args == {
|
assert foo_field.args == {
|
||||||
'bar': GraphQLArgument(GraphQLString, description='Argument description', default_value='x')
|
'bar': GraphQLArgument(GraphQLString, description='Argument description', default_value='x', out_name='bar')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -114,18 +114,18 @@ def test_interface():
|
||||||
assert foo_field.description == 'Field description'
|
assert foo_field.description == 'Field description'
|
||||||
assert not foo_field.resolver # Resolver not attached in interfaces
|
assert not foo_field.resolver # Resolver not attached in interfaces
|
||||||
assert foo_field.args == {
|
assert foo_field.args == {
|
||||||
'bar': GraphQLArgument(GraphQLString, description='Argument description', default_value='x')
|
'bar': GraphQLArgument(GraphQLString, description='Argument description', default_value='x', out_name='bar')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def test_inputobject():
|
def test_inputobject():
|
||||||
class MyInputObjectType(InputObjectType):
|
class MyInputObjectType(InputObjectType):
|
||||||
'''Description'''
|
'''Description'''
|
||||||
foo = String(description='Field description')
|
foo_bar = String(description='Field description')
|
||||||
bar = String(name='gizmo')
|
bar = String(name='gizmo')
|
||||||
own = InputField(lambda: MyInputObjectType)
|
own = InputField(lambda: MyInputObjectType)
|
||||||
|
|
||||||
def resolve_foo(self, args, info):
|
def resolve_foo_bar(self, args, info):
|
||||||
return args.get('bar')
|
return args.get('bar')
|
||||||
|
|
||||||
typemap = TypeMap([MyInputObjectType])
|
typemap = TypeMap([MyInputObjectType])
|
||||||
|
@ -136,8 +136,8 @@ def test_inputobject():
|
||||||
assert graphql_type.description == 'Description'
|
assert graphql_type.description == 'Description'
|
||||||
|
|
||||||
fields = graphql_type.fields
|
fields = graphql_type.fields
|
||||||
assert list(fields.keys()) == ['foo', 'gizmo', 'own']
|
assert list(fields.keys()) == ['fooBar', 'gizmo', 'own']
|
||||||
assert fields['own'].type == graphql_type
|
assert fields['own'].type == graphql_type
|
||||||
foo_field = fields['foo']
|
foo_field = fields['fooBar']
|
||||||
assert isinstance(foo_field, GraphQLInputObjectField)
|
assert isinstance(foo_field, GraphQLInputObjectField)
|
||||||
assert foo_field.description == 'Field description'
|
assert foo_field.description == 'Field description'
|
||||||
|
|
|
@ -206,6 +206,7 @@ class TypeMap(GraphQLTypeMap):
|
||||||
_field = GraphQLInputObjectField(
|
_field = GraphQLInputObjectField(
|
||||||
field_type,
|
field_type,
|
||||||
default_value=field.default_value,
|
default_value=field.default_value,
|
||||||
|
out_name=field.name or name,
|
||||||
description=field.description
|
description=field.description
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
|
@ -213,9 +214,10 @@ class TypeMap(GraphQLTypeMap):
|
||||||
for arg_name, arg in field.args.items():
|
for arg_name, arg in field.args.items():
|
||||||
map = cls.reducer(map, arg.type)
|
map = cls.reducer(map, arg.type)
|
||||||
arg_type = cls.get_field_type(map, arg.type)
|
arg_type = cls.get_field_type(map, arg.type)
|
||||||
arg_name = arg.name or cls.process_field_name(arg_name)
|
processed_arg_name = arg.name or cls.process_field_name(arg_name)
|
||||||
args[arg_name] = GraphQLArgument(
|
args[processed_arg_name] = GraphQLArgument(
|
||||||
arg_type,
|
arg_type,
|
||||||
|
out_name=arg.name or arg_name,
|
||||||
description=arg.description,
|
description=arg.description,
|
||||||
default_value=arg.default_value
|
default_value=arg.default_value
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user