Changed from mutation->is_mutation interface->is_interface

This commit is contained in:
Syrus Akbary 2015-10-26 02:27:45 -07:00
parent b377eb6230
commit ea5207d025
6 changed files with 25 additions and 25 deletions

View File

@ -60,7 +60,7 @@ class Field(object):
def get_resolve_fn(self, schema): def get_resolve_fn(self, schema):
object_type = self.get_object_type(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 return object_type.mutate
elif self.resolve_fn: elif self.resolve_fn:
return self.resolve_fn return self.resolve_fn
@ -109,7 +109,7 @@ class Field(object):
def internal_field(self, schema): def internal_field(self, schema):
if not self.object_type: if not self.object_type:
raise Exception( 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() extra_args = self.extra_args.copy()
for arg_name, arg_value in self.extra_args.items(): for arg_name, arg_value in self.extra_args.items():
@ -127,7 +127,7 @@ class Field(object):
args = self.args args = self.args
object_type = self.get_object_type(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:
assert not self.args, 'Arguments provided for mutations are defined in Input class in 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) args = object_type.input_type.fields_as_arguments(schema)

View File

@ -1,7 +1,7 @@
from graphene.utils import cached_property from graphene.utils import cached_property
from collections import OrderedDict, namedtuple from collections import OrderedDict, namedtuple
DEFAULT_NAMES = ('description', 'name', 'interface', 'mutation', DEFAULT_NAMES = ('description', 'name', 'is_interface', 'is_mutation',
'type_name', 'interfaces', 'proxy') 'type_name', 'interfaces', 'proxy')
@ -10,8 +10,8 @@ class Options(object):
def __init__(self, meta=None): def __init__(self, meta=None):
self.meta = meta self.meta = meta
self.local_fields = [] self.local_fields = []
self.interface = False self.is_interface = False
self.mutation = False self.is_mutation = False
self.proxy = False self.proxy = False
self.interfaces = [] self.interfaces = []
self.parents = [] self.parents = []

View File

@ -48,20 +48,20 @@ class ObjectTypeMeta(type):
new_class.add_to_class('_meta', new_class.options_cls(meta)) new_class.add_to_class('_meta', new_class.options_cls(meta))
new_class._meta.interface = new_class.is_interface(parents) new_class._meta.is_interface = new_class.is_interface(parents)
new_class._meta.mutation = new_class.is_mutation(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 input_class = None
if new_class._meta.mutation: if new_class._meta.is_mutation:
input_class = attrs.pop('Input', None) input_class = attrs.pop('Input', None)
# Add all attributes to the class. # Add all attributes to the class.
for obj_name, obj in attrs.items(): for obj_name, obj in attrs.items():
new_class.add_to_class(obj_name, obj) 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" assert hasattr(new_class, 'mutate'), "All mutations must implement mutate method"
if input_class: if input_class:
@ -103,7 +103,7 @@ class ObjectTypeMeta(type):
new_class.add_to_class(field.field_name, new_field) new_class.add_to_class(field.field_name, new_field)
new_class._meta.parents.append(base) new_class._meta.parents.append(base)
if base._meta.interface: if base._meta.is_interface:
new_class._meta.interfaces.append(base) new_class._meta.interfaces.append(base)
# new_class._meta.parents.extend(base._meta.parents) # new_class._meta.parents.extend(base._meta.parents)
@ -129,7 +129,7 @@ class ObjectTypeMeta(type):
class BaseObjectType(object): class BaseObjectType(object):
def __new__(cls, instance=None, **kwargs): def __new__(cls, instance=None, **kwargs):
if cls._meta.interface: if cls._meta.is_interface:
raise Exception("An interface cannot be initialized") raise Exception("An interface cannot be initialized")
if instance is None: if instance is None:
if not kwargs: if not kwargs:
@ -173,7 +173,7 @@ class BaseObjectType(object):
fields_list = cls._meta.fields fields_list = cls._meta.fields
fields = lambda: OrderedDict([(f.name, f.internal_field(schema)) fields = lambda: OrderedDict([(f.name, f.internal_field(schema))
for f in fields_list]) for f in fields_list])
if cls._meta.interface: if cls._meta.is_interface:
return GraphQLInterfaceType( return GraphQLInterfaceType(
cls._meta.type_name, cls._meta.type_name,
description=cls._meta.description, 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)): class ObjectType(six.with_metaclass(ObjectTypeMeta, BaseObjectType)):
pass pass
class Mutation(six.with_metaclass(ObjectTypeMeta, BaseObjectType)): class Mutation(six.with_metaclass(ObjectTypeMeta, BaseObjectType)):
pass pass
class Interface(six.with_metaclass(ObjectTypeMeta, BaseObjectType)):
pass

View File

@ -46,12 +46,12 @@ schema = Schema()
def test_django_interface(): def test_django_interface():
assert DjangoNode._meta.interface is True assert DjangoNode._meta.is_interface is True
def test_pseudo_interface(): def test_pseudo_interface():
object_type = Character.internal_type(schema) 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 isinstance(object_type, GraphQLInterfaceType)
assert Character._meta.model == Reporter assert Character._meta.model == Reporter
assert_equal_lists( assert_equal_lists(
@ -83,7 +83,7 @@ def test_interface_resolve_type():
def test_object_type(): def test_object_type():
object_type = Human.internal_type(schema) object_type = Human.internal_type(schema)
fields_map = Human._meta.fields_map 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 isinstance(object_type, GraphQLObjectType)
assert_equal_lists( assert_equal_lists(
object_type.get_fields().keys(), object_type.get_fields().keys(),
@ -99,5 +99,5 @@ def test_object_type():
def test_node_notinterface(): def test_node_notinterface():
assert Human._meta.interface is False assert Human._meta.is_interface is False
assert DjangoNode in Human._meta.interfaces assert DjangoNode in Human._meta.interfaces

View File

@ -10,7 +10,7 @@ from graphene.core.options import Options
class Meta: class Meta:
interface = True is_interface = True
type_name = 'Character' type_name = 'Character'

View File

@ -39,7 +39,7 @@ schema = Schema()
def test_interface(): def test_interface():
object_type = Character.internal_type(schema) 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 isinstance(object_type, GraphQLInterfaceType)
assert Character._meta.type_name == 'core_Character' assert Character._meta.type_name == 'core_Character'
assert object_type.description == 'Character description' assert object_type.description == 'Character description'
@ -55,7 +55,7 @@ def test_interface_resolve_type():
def test_object_type(): def test_object_type():
object_type = Human.internal_type(schema) 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 Human._meta.type_name == 'core_Human'
assert isinstance(object_type, GraphQLObjectType) assert isinstance(object_type, GraphQLObjectType)
assert object_type.description == 'Human description' assert object_type.description == 'Human description'