mirror of
				https://github.com/graphql-python/graphene.git
				synced 2025-10-26 05:31:05 +03:00 
			
		
		
		
	Improved relay coverage
This commit is contained in:
		
							parent
							
								
									7e901f83ae
								
							
						
					
					
						commit
						0a97deaa4d
					
				|  | @ -9,7 +9,6 @@ from ..types import (Boolean, Enum, Int, Interface, List, NonNull, Scalar, | |||
|                      String, Union) | ||||
| from ..types.field import Field | ||||
| from ..types.objecttype import ObjectType, ObjectTypeOptions | ||||
| from ..utils.deprecated import warn_deprecation | ||||
| from .node import is_node | ||||
| 
 | ||||
| 
 | ||||
|  | @ -101,7 +100,7 @@ class IterableConnectionField(Field): | |||
|         type = super(IterableConnectionField, self).type | ||||
|         connection_type = type | ||||
|         if is_node(type): | ||||
|             warn_deprecation( | ||||
|             raise Exception( | ||||
|                 "ConnectionField's now need a explicit ConnectionType for Nodes.\n" | ||||
|                 "Read more: https://github.com/graphql-python/graphene/blob/2.0/UPGRADE-v2.0.md#node-connections" | ||||
|             ) | ||||
|  |  | |||
|  | @ -14,10 +14,7 @@ class ClientIDMutation(Mutation): | |||
| 
 | ||||
|     @classmethod | ||||
|     def __init_subclass_with_meta__(cls, output=None, input_fields=None, | ||||
|                                     arguments=None, name=None, abstract=False, **options): | ||||
|         if abstract: | ||||
|             return | ||||
| 
 | ||||
|                                     arguments=None, name=None, **options): | ||||
|         input_class = getattr(cls, 'Input', None) | ||||
|         base_name = re.sub('Payload$', '', name or cls.__name__) | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,3 +1,4 @@ | |||
| import pytest | ||||
| 
 | ||||
| from ...types import Argument, Field, Int, List, NonNull, ObjectType, String | ||||
| from ..connection import Connection, ConnectionField, PageInfo | ||||
|  | @ -117,6 +118,13 @@ def test_connectionfield(): | |||
|     } | ||||
| 
 | ||||
| 
 | ||||
| def test_connectionfield_node_deprecated(): | ||||
|     field = ConnectionField(MyObject) | ||||
|     with pytest.raises(Exception) as exc_info: | ||||
|         field.type | ||||
|      | ||||
|     assert "ConnectionField's now need a explicit ConnectionType for Nodes." in str(exc_info.value) | ||||
| 
 | ||||
| def test_connectionfield_custom_args(): | ||||
|     class MyObjectConnection(Connection): | ||||
| 
 | ||||
|  |  | |||
|  | @ -31,6 +31,25 @@ class SaySomething(ClientIDMutation): | |||
|         return SaySomething(phrase=str(what)) | ||||
| 
 | ||||
| 
 | ||||
| class FixedSaySomething(object): | ||||
|     __slots__ = 'phrase', | ||||
| 
 | ||||
|     def __init__(self, phrase): | ||||
|         self.phrase = phrase | ||||
| 
 | ||||
| 
 | ||||
| class SaySomethingFixed(ClientIDMutation): | ||||
| 
 | ||||
|     class Input: | ||||
|         what = String() | ||||
| 
 | ||||
|     phrase = String() | ||||
| 
 | ||||
|     @staticmethod | ||||
|     def mutate_and_get_payload(self, info, what, client_mutation_id=None): | ||||
|         return FixedSaySomething(phrase=str(what)) | ||||
| 
 | ||||
| 
 | ||||
| class SaySomethingPromise(ClientIDMutation): | ||||
| 
 | ||||
|     class Input: | ||||
|  | @ -71,6 +90,7 @@ class RootQuery(ObjectType): | |||
| 
 | ||||
| class Mutation(ObjectType): | ||||
|     say = SaySomething.Field() | ||||
|     say_fixed = SaySomethingFixed.Field() | ||||
|     say_promise = SaySomethingPromise.Field() | ||||
|     other = OtherMutation.Field() | ||||
| 
 | ||||
|  | @ -152,7 +172,14 @@ def test_node_query(): | |||
|     assert executed.data == {'say': {'phrase': 'hello'}} | ||||
| 
 | ||||
| 
 | ||||
| def test_node_query(): | ||||
| def test_node_query_fixed(): | ||||
|     executed = schema.execute( | ||||
|         'mutation a { sayFixed(input: {what:"hello", clientMutationId:"1"}) { phrase } }' | ||||
|     ) | ||||
|     assert "Cannot set client_mutation_id in the payload object" in str(executed.errors[0]) | ||||
| 
 | ||||
| 
 | ||||
| def test_node_query_promise(): | ||||
|     executed = schema.execute( | ||||
|         'mutation a { sayPromise(input: {what:"hello", clientMutationId:"1"}) { phrase } }' | ||||
|     ) | ||||
|  |  | |||
|  | @ -3,7 +3,7 @@ from collections import OrderedDict | |||
| from graphql_relay import to_global_id | ||||
| 
 | ||||
| from ...types import ObjectType, Schema, String | ||||
| from ..node import Node | ||||
| from ..node import Node, is_node | ||||
| 
 | ||||
| 
 | ||||
| class SharedNodeFields(object): | ||||
|  | @ -46,11 +46,14 @@ class RootQuery(ObjectType): | |||
|     only_node = Node.Field(MyNode) | ||||
|     only_node_lazy = Node.Field(lambda: MyNode) | ||||
| 
 | ||||
| 
 | ||||
| schema = Schema(query=RootQuery, types=[MyNode, MyOtherNode]) | ||||
| 
 | ||||
| 
 | ||||
| def test_node_good(): | ||||
|     assert 'id' in MyNode._meta.fields | ||||
|     assert is_node(MyNode) | ||||
|     assert not is_node(object) | ||||
| 
 | ||||
| 
 | ||||
| def test_node_query(): | ||||
|  | @ -70,6 +73,15 @@ def test_subclassed_node_query(): | |||
|         [('shared', '1'), ('extraField', 'extra field info.'), ('somethingElse', '----')])}) | ||||
| 
 | ||||
| 
 | ||||
| def test_node_requesting_non_node(): | ||||
|     executed = schema.execute( | ||||
|         '{ node(id:"%s") { __typename } } ' % Node.to_global_id("RootQuery", 1) | ||||
|     ) | ||||
|     assert executed.data == { | ||||
|         'node': None | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
| def test_node_query_incorrect_id(): | ||||
|     executed = schema.execute( | ||||
|         '{ node(id:"%s") { ... on MyNode { name } } }' % "something:2" | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user