mirror of
				https://github.com/graphql-python/graphene.git
				synced 2025-10-30 23:47:55 +03:00 
			
		
		
		
	Merge pull request #1412 from loft-orbital/issue-#1394_fix-required
This commit is contained in:
		
						commit
						03277a5512
					
				|  | @ -49,7 +49,7 @@ type Faction implements Node { | |||
|   name: String | ||||
| 
 | ||||
|   """The ships used by the faction.""" | ||||
|   ships(before: String = null, after: String = null, first: Int = null, last: Int = null): ShipConnection | ||||
|   ships(before: String, after: String, first: Int, last: Int): ShipConnection | ||||
| } | ||||
| 
 | ||||
| """An object with an ID""" | ||||
|  |  | |||
|  | @ -86,6 +86,8 @@ class Node(AbstractNode): | |||
|     def get_node_from_global_id(cls, info, global_id, only_type=None): | ||||
|         try: | ||||
|             _type, _id = cls.from_global_id(global_id) | ||||
|             if not _type: | ||||
|                 raise ValueError("Invalid Global ID") | ||||
|         except Exception as e: | ||||
|             raise Exception( | ||||
|                 f'Unable to parse global ID "{global_id}". ' | ||||
|  |  | |||
							
								
								
									
										36
									
								
								graphene/tests/issues/test_1394.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								graphene/tests/issues/test_1394.py
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,36 @@ | |||
| from ...types import ObjectType, Schema, String, NonNull | ||||
| 
 | ||||
| 
 | ||||
| class Query(ObjectType): | ||||
|     hello = String(input=NonNull(String)) | ||||
| 
 | ||||
|     def resolve_hello(self, info, input): | ||||
|         if input == "nothing": | ||||
|             return None | ||||
|         return f"Hello {input}!" | ||||
| 
 | ||||
| 
 | ||||
| schema = Schema(query=Query) | ||||
| 
 | ||||
| 
 | ||||
| def test_required_input_provided(): | ||||
|     """ | ||||
|     Test that a required argument works when provided. | ||||
|     """ | ||||
|     input_value = "Potato" | ||||
|     result = schema.execute('{ hello(input: "%s") }' % input_value) | ||||
|     assert not result.errors | ||||
|     assert result.data == {"hello": "Hello Potato!"} | ||||
| 
 | ||||
| 
 | ||||
| def test_required_input_missing(): | ||||
|     """ | ||||
|     Test that a required argument raised an error if not provided. | ||||
|     """ | ||||
|     result = schema.execute("{ hello }") | ||||
|     assert result.errors | ||||
|     assert len(result.errors) == 1 | ||||
|     assert ( | ||||
|         result.errors[0].message | ||||
|         == "Field 'hello' argument 'input' of type 'String!' is required, but it was not provided." | ||||
|     ) | ||||
|  | @ -1,4 +1,5 @@ | |||
| from itertools import chain | ||||
| from graphql import Undefined | ||||
| 
 | ||||
| from .dynamic import Dynamic | ||||
| from .mountedtype import MountedType | ||||
|  | @ -41,7 +42,7 @@ class Argument(MountedType): | |||
|     def __init__( | ||||
|         self, | ||||
|         type_, | ||||
|         default_value=None, | ||||
|         default_value=Undefined, | ||||
|         description=None, | ||||
|         name=None, | ||||
|         required=False, | ||||
|  |  | |||
|  | @ -229,11 +229,11 @@ def test_query_arguments(): | |||
| 
 | ||||
|     result = test_schema.execute("{ test }", None) | ||||
|     assert not result.errors | ||||
|     assert result.data == {"test": '[null,{"a_str":null,"a_int":null}]'} | ||||
|     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!","a_int":null}]'} | ||||
|     assert result.data == {"test": '["Source!",{"a_str":"String!"}]'} | ||||
| 
 | ||||
|     result = test_schema.execute('{ test(aInt: -123, aStr: "String!") }', "Source!") | ||||
|     assert not result.errors | ||||
|  | @ -258,7 +258,7 @@ def test_query_input_field(): | |||
| 
 | ||||
|     result = test_schema.execute("{ test }", None) | ||||
|     assert not result.errors | ||||
|     assert result.data == {"test": '[null,{"a_input":null}]'} | ||||
|     assert result.data == {"test": "[null,{}]"} | ||||
| 
 | ||||
|     result = test_schema.execute('{ test(aInput: {aField: "String!"} ) }', "Source!") | ||||
|     assert not result.errors | ||||
|  |  | |||
|  | @ -1,3 +1,4 @@ | |||
| from graphql import Undefined | ||||
| from graphql.type import ( | ||||
|     GraphQLArgument, | ||||
|     GraphQLEnumType, | ||||
|  | @ -244,7 +245,9 @@ def test_objecttype_camelcase(): | |||
|     foo_field = fields["fooBar"] | ||||
|     assert isinstance(foo_field, GraphQLField) | ||||
|     assert foo_field.args == { | ||||
|         "barFoo": GraphQLArgument(GraphQLString, default_value=None, out_name="bar_foo") | ||||
|         "barFoo": GraphQLArgument( | ||||
|             GraphQLString, default_value=Undefined, out_name="bar_foo" | ||||
|         ) | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
|  | @ -267,7 +270,7 @@ def test_objecttype_camelcase_disabled(): | |||
|     assert isinstance(foo_field, GraphQLField) | ||||
|     assert foo_field.args == { | ||||
|         "bar_foo": GraphQLArgument( | ||||
|             GraphQLString, default_value=None, out_name="bar_foo" | ||||
|             GraphQLString, default_value=Undefined, out_name="bar_foo" | ||||
|         ) | ||||
|     } | ||||
| 
 | ||||
|  |  | |||
|  | @ -94,6 +94,7 @@ TEST_DATA = { | |||
|     ], | ||||
|     "movies": { | ||||
|         "1198359": { | ||||
|             "id": "1198359", | ||||
|             "name": "King Arthur: Legend of the Sword", | ||||
|             "synopsis": ( | ||||
|                 "When the child Arthur's father is murdered, Vortigern, " | ||||
|  | @ -159,7 +160,7 @@ def test_example_end_to_end(): | |||
|                 "date": "2017-05-19", | ||||
|                 "movie": { | ||||
|                     "__typename": "Movie", | ||||
|                     "id": "TW92aWU6Tm9uZQ==", | ||||
|                     "id": "TW92aWU6MTE5ODM1OQ==", | ||||
|                     "name": "King Arthur: Legend of the Sword", | ||||
|                     "synopsis": ( | ||||
|                         "When the child Arthur's father is murdered, Vortigern, " | ||||
|  | @ -172,7 +173,7 @@ def test_example_end_to_end(): | |||
|                 "__typename": "Event", | ||||
|                 "id": "RXZlbnQ6MjM0", | ||||
|                 "date": "2017-05-20", | ||||
|                 "movie": {"__typename": "Movie", "id": "TW92aWU6Tm9uZQ=="}, | ||||
|                 "movie": {"__typename": "Movie", "id": "TW92aWU6MTE5ODM1OQ=="}, | ||||
|             }, | ||||
|         ] | ||||
|     } | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user