|
3 | 3 |
|
4 | 4 | from graphql import graphql |
5 | 5 | from graphql.type import (GraphQLArgument, GraphQLField, GraphQLInt, |
6 | | - GraphQLObjectType, GraphQLSchema, GraphQLString) |
| 6 | + GraphQLObjectType, GraphQLSchema, GraphQLString, |
| 7 | + GraphQLInputObjectType, GraphQLInputObjectField, |
| 8 | + GraphQLNonNull, GraphQLList) |
7 | 9 |
|
8 | 10 |
|
9 | 11 | def _test_schema(test_field): |
@@ -69,3 +71,68 @@ def resolver(source, args, *_): |
69 | 71 | {'test': '["Source!",{"aStr":"String!","aInt":-123}]'}, |
70 | 72 | {'test': '["Source!",{"aInt":-123,"aStr":"String!"}]'} |
71 | 73 | ] |
| 74 | + |
| 75 | + |
| 76 | +def test_maps_argument_out_names_well(): |
| 77 | + def resolver(source, args, *_): |
| 78 | + return json.dumps([source, args], separators=(',', ':')) |
| 79 | + |
| 80 | + schema = _test_schema(GraphQLField( |
| 81 | + GraphQLString, |
| 82 | + args=OrderedDict([ |
| 83 | + ('aStr', GraphQLArgument(GraphQLString, out_name="a_str")), |
| 84 | + ('aInt', GraphQLArgument(GraphQLInt, out_name="a_int")), |
| 85 | + ]), |
| 86 | + resolver=resolver |
| 87 | + )) |
| 88 | + |
| 89 | + result = graphql(schema, '{ test }', None) |
| 90 | + assert not result.errors |
| 91 | + assert result.data == {'test': '[null,{}]'} |
| 92 | + |
| 93 | + result = graphql(schema, '{ test(aStr: "String!") }', 'Source!') |
| 94 | + assert not result.errors |
| 95 | + assert result.data == {'test': '["Source!",{"a_str":"String!"}]'} |
| 96 | + |
| 97 | + result = graphql(schema, '{ test(aInt: -123, aStr: "String!",) }', 'Source!') |
| 98 | + assert not result.errors |
| 99 | + assert result.data in [ |
| 100 | + {'test': '["Source!",{"a_str":"String!","a_int":-123}]'}, |
| 101 | + {'test': '["Source!",{"a_int":-123,"a_str":"String!"}]'} |
| 102 | + ] |
| 103 | + |
| 104 | + |
| 105 | +def test_maps_argument_out_names_well_with_input(): |
| 106 | + def resolver(source, args, *_): |
| 107 | + return json.dumps([source, args], separators=(',', ':')) |
| 108 | + |
| 109 | + |
| 110 | + TestInputObject = GraphQLInputObjectType('TestInputObject', lambda: OrderedDict([ |
| 111 | + ('inputOne', GraphQLInputObjectField(GraphQLString, out_name="input_one")), |
| 112 | + ('inputRecursive', GraphQLInputObjectField(TestInputObject, out_name="input_recursive")), |
| 113 | + ])) |
| 114 | + |
| 115 | + schema = _test_schema(GraphQLField( |
| 116 | + GraphQLString, |
| 117 | + args=OrderedDict([ |
| 118 | + ('aStr', GraphQLArgument(GraphQLString, out_name="a_str")), |
| 119 | + ('aInt', GraphQLArgument(GraphQLInt, out_name="a_int")), |
| 120 | + ('aInput', GraphQLArgument(TestInputObject, out_name="a_input")) |
| 121 | + ]), |
| 122 | + resolver=resolver |
| 123 | + )) |
| 124 | + |
| 125 | + result = graphql(schema, '{ test }', None) |
| 126 | + assert not result.errors |
| 127 | + assert result.data == {'test': '[null,{}]'} |
| 128 | + |
| 129 | + result = graphql(schema, '{ test(aInput: {inputOne: "String!"} ) }', 'Source!') |
| 130 | + assert not result.errors |
| 131 | + assert result.data == {'test': '["Source!",{"a_input":{"input_one":"String!"}}]'} |
| 132 | + |
| 133 | + result = graphql(schema, '{ test(aInput: {inputOne: "String!", inputRecursive:{inputOne: "SourceRecursive!"}} ) }', 'Source!') |
| 134 | + assert not result.errors |
| 135 | + assert result.data in [ |
| 136 | + {'test': '["Source!",{"a_input":{"input_one":"String!","input_recursive":{"input_one":"SourceRecursive!"}}}]'}, |
| 137 | + {'test': '["Source!",{"a_input":{"input_recursive":{"input_one":"SourceRecursive!"}},"input_one":"String!"}]'} |
| 138 | + ] |
0 commit comments