From 0a97deaa4d262229d65298f6a28f5c4193a9908b Mon Sep 17 00:00:00 2001 From: Syrus Akbary Date: Tue, 1 Aug 2017 23:55:39 -0700 Subject: [PATCH] Improved relay coverage --- graphene/relay/connection.py | 3 +-- graphene/relay/mutation.py | 5 +---- graphene/relay/tests/test_connection.py | 8 +++++++ graphene/relay/tests/test_mutation.py | 29 ++++++++++++++++++++++++- graphene/relay/tests/test_node.py | 14 +++++++++++- 5 files changed, 51 insertions(+), 8 deletions(-) diff --git a/graphene/relay/connection.py b/graphene/relay/connection.py index e480f036..afe6ffb3 100644 --- a/graphene/relay/connection.py +++ b/graphene/relay/connection.py @@ -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" ) diff --git a/graphene/relay/mutation.py b/graphene/relay/mutation.py index 97b72417..8c020ef0 100644 --- a/graphene/relay/mutation.py +++ b/graphene/relay/mutation.py @@ -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__) diff --git a/graphene/relay/tests/test_connection.py b/graphene/relay/tests/test_connection.py index c769eb89..b6a26df3 100644 --- a/graphene/relay/tests/test_connection.py +++ b/graphene/relay/tests/test_connection.py @@ -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): diff --git a/graphene/relay/tests/test_mutation.py b/graphene/relay/tests/test_mutation.py index 97a58028..aa5ce179 100644 --- a/graphene/relay/tests/test_mutation.py +++ b/graphene/relay/tests/test_mutation.py @@ -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 } }' ) diff --git a/graphene/relay/tests/test_node.py b/graphene/relay/tests/test_node.py index 315f2e39..10dc5d94 100644 --- a/graphene/relay/tests/test_node.py +++ b/graphene/relay/tests/test_node.py @@ -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"