mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-26 11:33:55 +03:00
Improved is_node checks
This commit is contained in:
parent
bb6dc43d4b
commit
2cc701f444
|
@ -1,5 +1,6 @@
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
from inspect import isclass
|
||||||
|
|
||||||
from graphql_relay import from_global_id, to_global_id
|
from graphql_relay import from_global_id, to_global_id
|
||||||
|
|
||||||
|
@ -12,12 +13,16 @@ def is_node(objecttype):
|
||||||
'''
|
'''
|
||||||
Check if the given objecttype has Node as an interface
|
Check if the given objecttype has Node as an interface
|
||||||
'''
|
'''
|
||||||
|
if not isclass(objecttype):
|
||||||
|
return False
|
||||||
|
|
||||||
if not issubclass(objecttype, ObjectType):
|
if not issubclass(objecttype, ObjectType):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
for i in objecttype._meta.interfaces:
|
for i in objecttype._meta.interfaces:
|
||||||
if issubclass(i, Node):
|
if issubclass(i, Node):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
@ -49,7 +54,8 @@ class NodeField(Field):
|
||||||
self.field_type = type
|
self.field_type = type
|
||||||
|
|
||||||
super(NodeField, self).__init__(
|
super(NodeField, self).__init__(
|
||||||
# If we don's specify a type, the field type will be the node interface
|
# If we don's specify a type, the field type will be the node
|
||||||
|
# interface
|
||||||
type or node,
|
type or node,
|
||||||
description='The ID of the object',
|
description='The ID of the object',
|
||||||
id=ID(required=True)
|
id=ID(required=True)
|
||||||
|
@ -70,7 +76,8 @@ class AbstractNode(Interface):
|
||||||
_meta.fields = OrderedDict(
|
_meta.fields = OrderedDict(
|
||||||
id=GlobalID(cls, description='The ID of the object.')
|
id=GlobalID(cls, description='The ID of the object.')
|
||||||
)
|
)
|
||||||
super(AbstractNode, cls).__init_subclass_with_meta__(_meta=_meta, **options)
|
super(AbstractNode, cls).__init_subclass_with_meta__(
|
||||||
|
_meta=_meta, **options)
|
||||||
|
|
||||||
|
|
||||||
class Node(AbstractNode):
|
class Node(AbstractNode):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user