mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-11 04:07:16 +03:00
Changed from mutation->is_mutation interface->is_interface
This commit is contained in:
parent
b377eb6230
commit
ea5207d025
|
@ -60,7 +60,7 @@ class Field(object):
|
|||
|
||||
def get_resolve_fn(self, schema):
|
||||
object_type = self.get_object_type(schema)
|
||||
if object_type and object_type._meta.mutation:
|
||||
if object_type and object_type._meta.is_mutation:
|
||||
return object_type.mutate
|
||||
elif self.resolve_fn:
|
||||
return self.resolve_fn
|
||||
|
@ -109,7 +109,7 @@ class Field(object):
|
|||
def internal_field(self, schema):
|
||||
if not self.object_type:
|
||||
raise Exception(
|
||||
'Field could not be constructed in a non graphene.Type or graphene.Interface')
|
||||
'Field could not be constructed in a non graphene.ObjectType or graphene.Interface')
|
||||
|
||||
extra_args = self.extra_args.copy()
|
||||
for arg_name, arg_value in self.extra_args.items():
|
||||
|
@ -127,7 +127,7 @@ class Field(object):
|
|||
args = self.args
|
||||
|
||||
object_type = self.get_object_type(schema)
|
||||
if object_type and object_type._meta.mutation:
|
||||
if object_type and object_type._meta.is_mutation:
|
||||
assert not self.args, 'Arguments provided for mutations are defined in Input class in Mutation'
|
||||
args = object_type.input_type.fields_as_arguments(schema)
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
from graphene.utils import cached_property
|
||||
from collections import OrderedDict, namedtuple
|
||||
|
||||
DEFAULT_NAMES = ('description', 'name', 'interface', 'mutation',
|
||||
DEFAULT_NAMES = ('description', 'name', 'is_interface', 'is_mutation',
|
||||
'type_name', 'interfaces', 'proxy')
|
||||
|
||||
|
||||
|
@ -10,8 +10,8 @@ class Options(object):
|
|||
def __init__(self, meta=None):
|
||||
self.meta = meta
|
||||
self.local_fields = []
|
||||
self.interface = False
|
||||
self.mutation = False
|
||||
self.is_interface = False
|
||||
self.is_mutation = False
|
||||
self.proxy = False
|
||||
self.interfaces = []
|
||||
self.parents = []
|
||||
|
|
|
@ -48,20 +48,20 @@ class ObjectTypeMeta(type):
|
|||
|
||||
new_class.add_to_class('_meta', new_class.options_cls(meta))
|
||||
|
||||
new_class._meta.interface = new_class.is_interface(parents)
|
||||
new_class._meta.mutation = new_class.is_mutation(parents)
|
||||
new_class._meta.is_interface = new_class.is_interface(parents)
|
||||
new_class._meta.is_mutation = new_class.is_mutation(parents)
|
||||
|
||||
assert not (new_class._meta.interface and new_class._meta.mutation)
|
||||
assert not (new_class._meta.is_interface and new_class._meta.is_mutation)
|
||||
|
||||
input_class = None
|
||||
if new_class._meta.mutation:
|
||||
if new_class._meta.is_mutation:
|
||||
input_class = attrs.pop('Input', None)
|
||||
|
||||
# Add all attributes to the class.
|
||||
for obj_name, obj in attrs.items():
|
||||
new_class.add_to_class(obj_name, obj)
|
||||
|
||||
if new_class._meta.mutation:
|
||||
if new_class._meta.is_mutation:
|
||||
assert hasattr(new_class, 'mutate'), "All mutations must implement mutate method"
|
||||
|
||||
if input_class:
|
||||
|
@ -103,7 +103,7 @@ class ObjectTypeMeta(type):
|
|||
new_class.add_to_class(field.field_name, new_field)
|
||||
|
||||
new_class._meta.parents.append(base)
|
||||
if base._meta.interface:
|
||||
if base._meta.is_interface:
|
||||
new_class._meta.interfaces.append(base)
|
||||
# new_class._meta.parents.extend(base._meta.parents)
|
||||
|
||||
|
@ -129,7 +129,7 @@ class ObjectTypeMeta(type):
|
|||
class BaseObjectType(object):
|
||||
|
||||
def __new__(cls, instance=None, **kwargs):
|
||||
if cls._meta.interface:
|
||||
if cls._meta.is_interface:
|
||||
raise Exception("An interface cannot be initialized")
|
||||
if instance is None:
|
||||
if not kwargs:
|
||||
|
@ -173,7 +173,7 @@ class BaseObjectType(object):
|
|||
fields_list = cls._meta.fields
|
||||
fields = lambda: OrderedDict([(f.name, f.internal_field(schema))
|
||||
for f in fields_list])
|
||||
if cls._meta.interface:
|
||||
if cls._meta.is_interface:
|
||||
return GraphQLInterfaceType(
|
||||
cls._meta.type_name,
|
||||
description=cls._meta.description,
|
||||
|
@ -190,13 +190,13 @@ class BaseObjectType(object):
|
|||
)
|
||||
|
||||
|
||||
class Interface(six.with_metaclass(ObjectTypeMeta, BaseObjectType)):
|
||||
pass
|
||||
|
||||
|
||||
class ObjectType(six.with_metaclass(ObjectTypeMeta, BaseObjectType)):
|
||||
pass
|
||||
|
||||
|
||||
class Mutation(six.with_metaclass(ObjectTypeMeta, BaseObjectType)):
|
||||
pass
|
||||
|
||||
|
||||
class Interface(six.with_metaclass(ObjectTypeMeta, BaseObjectType)):
|
||||
pass
|
||||
|
|
|
@ -46,12 +46,12 @@ schema = Schema()
|
|||
|
||||
|
||||
def test_django_interface():
|
||||
assert DjangoNode._meta.interface is True
|
||||
assert DjangoNode._meta.is_interface is True
|
||||
|
||||
|
||||
def test_pseudo_interface():
|
||||
object_type = Character.internal_type(schema)
|
||||
assert Character._meta.interface is True
|
||||
assert Character._meta.is_interface is True
|
||||
assert isinstance(object_type, GraphQLInterfaceType)
|
||||
assert Character._meta.model == Reporter
|
||||
assert_equal_lists(
|
||||
|
@ -83,7 +83,7 @@ def test_interface_resolve_type():
|
|||
def test_object_type():
|
||||
object_type = Human.internal_type(schema)
|
||||
fields_map = Human._meta.fields_map
|
||||
assert Human._meta.interface is False
|
||||
assert Human._meta.is_interface is False
|
||||
assert isinstance(object_type, GraphQLObjectType)
|
||||
assert_equal_lists(
|
||||
object_type.get_fields().keys(),
|
||||
|
@ -99,5 +99,5 @@ def test_object_type():
|
|||
|
||||
|
||||
def test_node_notinterface():
|
||||
assert Human._meta.interface is False
|
||||
assert Human._meta.is_interface is False
|
||||
assert DjangoNode in Human._meta.interfaces
|
||||
|
|
|
@ -10,7 +10,7 @@ from graphene.core.options import Options
|
|||
|
||||
|
||||
class Meta:
|
||||
interface = True
|
||||
is_interface = True
|
||||
type_name = 'Character'
|
||||
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ schema = Schema()
|
|||
|
||||
def test_interface():
|
||||
object_type = Character.internal_type(schema)
|
||||
assert Character._meta.interface is True
|
||||
assert Character._meta.is_interface is True
|
||||
assert isinstance(object_type, GraphQLInterfaceType)
|
||||
assert Character._meta.type_name == 'core_Character'
|
||||
assert object_type.description == 'Character description'
|
||||
|
@ -55,7 +55,7 @@ def test_interface_resolve_type():
|
|||
|
||||
def test_object_type():
|
||||
object_type = Human.internal_type(schema)
|
||||
assert Human._meta.interface is False
|
||||
assert Human._meta.is_interface is False
|
||||
assert Human._meta.type_name == 'core_Human'
|
||||
assert isinstance(object_type, GraphQLObjectType)
|
||||
assert object_type.description == 'Human description'
|
||||
|
|
Loading…
Reference in New Issue
Block a user