Skip to content

Commit 8abcaff

Browse files
committed
Improved classtypes core support
1 parent 398f7da commit 8abcaff

File tree

9 files changed

+38
-565
lines changed

9 files changed

+38
-565
lines changed

graphene/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,15 @@
88
Schema
99
)
1010

11-
from graphene.core.types import (
11+
from graphene.core.classtypes import (
1212
ObjectType,
1313
InputObjectType,
1414
Interface,
1515
Mutation,
16+
Scalar
17+
)
18+
19+
from graphene.core.types import (
1620
BaseType,
1721
LazyType,
1822
Argument,
@@ -59,6 +63,7 @@
5963
'InputObjectType',
6064
'Interface',
6165
'Mutation',
66+
'Scalar',
6267
'Field',
6368
'InputField',
6469
'StringField',

graphene/core/classtypes/__init__.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from .inputobjecttype import InputObjectType
2+
from .interface import Interface
3+
from .mutation import Mutation
4+
from .objecttype import ObjectType
5+
from .options import Options
6+
from .scalar import Scalar
7+
from .uniontype import UnionType
8+
9+
__all__ = [
10+
'InputObjectType',
11+
'Interface',
12+
'Mutation',
13+
'ObjectType',
14+
'Options',
15+
'Scalar',
16+
'UnionType']

graphene/core/options.py

Lines changed: 0 additions & 72 deletions
This file was deleted.

graphene/core/schema.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from graphene import signals
1212

1313
from .types.base import BaseType
14-
from .types.objecttype import BaseObjectType
1514
from .classtypes.base import ClassType
1615

1716

@@ -49,7 +48,7 @@ def T(self, object_type):
4948
internal_type = object_type.internal_type(self)
5049
self._types[object_type] = internal_type
5150
is_objecttype = inspect.isclass(
52-
object_type) and issubclass(object_type, BaseObjectType)
51+
object_type) and issubclass(object_type, ClassType)
5352
if is_objecttype:
5453
self.register(object_type)
5554
return self._types[object_type]
@@ -91,7 +90,7 @@ def objecttype(self, type):
9190
if name:
9291
objecttype = self._types_names.get(name, None)
9392
if objecttype and inspect.isclass(
94-
objecttype) and issubclass(objecttype, BaseObjectType):
93+
objecttype) and issubclass(objecttype, ClassType):
9594
return objecttype
9695

9796
def __str__(self):

graphene/core/types/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
from .base import BaseType, LazyType, OrderedType
22
from .argument import Argument, ArgumentsGroup, to_arguments
33
from .definitions import List, NonNull
4-
from .objecttype import ObjectTypeMeta, BaseObjectType, Interface, ObjectType, Mutation, InputObjectType
4+
# Compatibility import
5+
from .objecttype import Interface, ObjectType, Mutation, InputObjectType
6+
57
from .scalars import String, ID, Boolean, Int, Float, Scalar
68
from .field import Field, InputField
79

@@ -17,8 +19,6 @@
1719
'Field',
1820
'InputField',
1921
'Interface',
20-
'BaseObjectType',
21-
'ObjectTypeMeta',
2222
'ObjectType',
2323
'Mutation',
2424
'InputObjectType',

graphene/core/types/base.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22

33
import six
44

5-
from ..classtypes.base import FieldsClassType
6-
from ..classtypes.inputobjecttype import InputObjectType as NewInputObjectType
7-
85

96
class BaseType(object):
107

@@ -107,11 +104,12 @@ def as_argument(self):
107104
class FieldType(MirroredType):
108105

109106
def contribute_to_class(self, cls, name):
110-
from ..types import BaseObjectType, InputObjectType
111-
if issubclass(cls, (InputObjectType, NewInputObjectType)):
107+
from ..classtypes.base import FieldsClassType
108+
from ..classtypes.inputobjecttype import InputObjectType
109+
if issubclass(cls, (InputObjectType)):
112110
inputfield = self.as_inputfield()
113111
return inputfield.contribute_to_class(cls, name)
114-
elif issubclass(cls, (BaseObjectType, FieldsClassType)):
112+
elif issubclass(cls, (FieldsClassType)):
115113
field = self.as_field()
116114
return field.contribute_to_class(cls, name)
117115

graphene/core/types/field.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
from ...utils import to_camel_case
88
from ..classtypes.base import FieldsClassType
9-
from ..classtypes.inputobjecttype import InputObjectType as NewInputObjectType
10-
from ..types import BaseObjectType, InputObjectType
9+
from ..classtypes.mutation import Mutation
10+
from ..classtypes.inputobjecttype import InputObjectType
1111
from .argument import ArgumentsGroup, snake_case_args
1212
from .base import LazyType, MountType, OrderedType
1313
from .definitions import NonNull
@@ -34,7 +34,7 @@ def __init__(
3434

3535
def contribute_to_class(self, cls, attname):
3636
assert issubclass(
37-
cls, (BaseObjectType, FieldsClassType)), 'Field {} cannot be mounted in {}'.format(
37+
cls, (FieldsClassType)), 'Field {} cannot be mounted in {}'.format(
3838
self, cls)
3939
if not self.name:
4040
self.name = to_camel_case(attname)
@@ -71,7 +71,7 @@ def internal_type(self, schema):
7171
description = resolver.__doc__
7272
type = schema.T(self.get_type(schema))
7373
type_objecttype = schema.objecttype(type)
74-
if type_objecttype and type_objecttype._meta.is_mutation:
74+
if type_objecttype and issubclass(type_objecttype, Mutation):
7575
assert len(arguments) == 0
7676
arguments = type_objecttype.get_arguments()
7777
resolver = getattr(type_objecttype, 'mutate')
@@ -128,7 +128,7 @@ def __init__(self, type, description=None, default=None,
128128

129129
def contribute_to_class(self, cls, attname):
130130
assert issubclass(
131-
cls, (InputObjectType, NewInputObjectType)), 'InputField {} cannot be mounted in {}'.format(
131+
cls, (InputObjectType)), 'InputField {} cannot be mounted in {}'.format(
132132
self, cls)
133133
if not self.name:
134134
self.name = to_camel_case(attname)

0 commit comments

Comments
 (0)