Fixed mutation input inheritance

This commit is contained in:
Syrus Akbary 2016-08-16 23:43:10 -07:00
parent 8e5555a044
commit 135a171fe4
3 changed files with 13 additions and 8 deletions

View File

@ -4,7 +4,7 @@ from functools import partial
import six import six
from promise import Promise from promise import Promise
from ..types import Argument, Field, InputObjectType, String from ..types import Argument, Field, InputObjectType, String, AbstractType
from ..types.objecttype import ObjectType, ObjectTypeMeta from ..types.objecttype import ObjectType, ObjectTypeMeta
from ..utils.is_base_type import is_base_type from ..utils.is_base_type import is_base_type
from ..utils.props import props from ..utils.props import props
@ -27,9 +27,14 @@ class ClientIDMutationMeta(ObjectTypeMeta):
"{}.mutate_and_get_payload method is required" "{}.mutate_and_get_payload method is required"
" in a ClientIDMutation." " in a ClientIDMutation."
).format(name) ).format(name)
input_attrs = props(input_class) if input_class else {} input_attrs = {}
bases = ()
if not issubclass(input_class, AbstractType):
input_attrs = props(input_class) if input_class else {}
else:
bases += (input_class, )
input_attrs['client_mutation_id'] = String(name='clientMutationId') input_attrs['client_mutation_id'] = String(name='clientMutationId')
cls.Input = type('{}Input'.format(base_name), (InputObjectType,), input_attrs) cls.Input = type('{}Input'.format(base_name), bases + (InputObjectType,), input_attrs)
cls.Field = partial(Field, cls, resolver=cls.mutate, input=Argument(cls.Input)) cls.Field = partial(Field, cls, resolver=cls.mutate, input=Argument(cls.Input))
return cls return cls

View File

@ -1,12 +1,12 @@
import pytest import pytest
from ...types import (Argument, Field, InputField, InputObjectType, ObjectType, from ...types import (Argument, Field, InputField, InputObjectType, ObjectType,
Schema) Schema, AbstractType)
from ...types.scalars import String from ...types.scalars import String
from ..mutation import ClientIDMutation from ..mutation import ClientIDMutation
class SharedFields(object): class SharedFields(AbstractType):
shared = String() shared = String()

View File

@ -10,9 +10,6 @@ from ..node import Node
class SharedNodeFields(AbstractType): class SharedNodeFields(AbstractType):
class Meta:
interfaces = (Node, )
shared = String() shared = String()
something_else = String() something_else = String()
@ -34,6 +31,9 @@ class MyNode(ObjectType):
class MyOtherNode(SharedNodeFields, ObjectType): class MyOtherNode(SharedNodeFields, ObjectType):
extra_field = String() extra_field = String()
class Meta:
interfaces = (Node, )
def resolve_extra_field(self, *_): def resolve_extra_field(self, *_):
return 'extra field info.' return 'extra field info.'