mirror of
https://github.com/graphql-python/graphene.git
synced 2025-02-08 23:50:38 +03:00
Improved ObjectType instances
This commit is contained in:
parent
311209760d
commit
c79097879d
10
README.md
10
README.md
|
@ -51,8 +51,6 @@ class Query(graphene.ObjectType):
|
||||||
@resolve_only_args
|
@resolve_only_args
|
||||||
def resolve_human(self, id):
|
def resolve_human(self, id):
|
||||||
return wrap_character(getHuman(id))
|
return wrap_character(getHuman(id))
|
||||||
if human:
|
|
||||||
return Human(human)
|
|
||||||
|
|
||||||
@resolve_only_args
|
@resolve_only_args
|
||||||
def resolve_droid(self, id):
|
def resolve_droid(self, id):
|
||||||
|
@ -91,9 +89,7 @@ class Ship(relay.Node):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_node(cls, id):
|
def get_node(cls, id):
|
||||||
ship = getShip(id)
|
return Ship(getShip(id))
|
||||||
if ship:
|
|
||||||
return Ship(ship)
|
|
||||||
|
|
||||||
|
|
||||||
class Faction(relay.Node):
|
class Faction(relay.Node):
|
||||||
|
@ -107,9 +103,7 @@ class Faction(relay.Node):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_node(cls, id):
|
def get_node(cls, id):
|
||||||
faction = getFaction(id)
|
return Faction(getFaction(id)
|
||||||
if faction:
|
|
||||||
return Faction(faction)
|
|
||||||
|
|
||||||
|
|
||||||
class Query(graphene.ObjectType):
|
class Query(graphene.ObjectType):
|
||||||
|
|
|
@ -43,10 +43,11 @@ class Schema(object):
|
||||||
return self._types[type_name]
|
return self._types[type_name]
|
||||||
|
|
||||||
def execute(self, request='', root=None, vars=None, operation_name=None):
|
def execute(self, request='', root=None, vars=None, operation_name=None):
|
||||||
|
root = root or object()
|
||||||
return graphql(
|
return graphql(
|
||||||
self._schema,
|
self._schema,
|
||||||
request=request,
|
request=request,
|
||||||
root=root or self.query(),
|
root=self.query(root),
|
||||||
vars=vars,
|
vars=vars,
|
||||||
operation_name=operation_name
|
operation_name=operation_name
|
||||||
)
|
)
|
||||||
|
|
|
@ -83,6 +83,13 @@ class ObjectTypeMeta(type):
|
||||||
|
|
||||||
|
|
||||||
class ObjectType(six.with_metaclass(ObjectTypeMeta)):
|
class ObjectType(six.with_metaclass(ObjectTypeMeta)):
|
||||||
|
def __new__(cls, instance=None, *args, **kwargs):
|
||||||
|
if cls._meta.interface:
|
||||||
|
raise Exception("An interface cannot be initialized")
|
||||||
|
if instance == None:
|
||||||
|
return None
|
||||||
|
return super(ObjectType, cls).__new__(cls, instance, *args, **kwargs)
|
||||||
|
|
||||||
def __init__(self, instance=None):
|
def __init__(self, instance=None):
|
||||||
signals.pre_init.send(self.__class__, instance=instance)
|
signals.pre_init.send(self.__class__, instance=instance)
|
||||||
self.instance = instance
|
self.instance = instance
|
||||||
|
@ -136,6 +143,7 @@ class Interface(ObjectType):
|
||||||
interface = True
|
interface = True
|
||||||
proxy = True
|
proxy = True
|
||||||
|
|
||||||
|
|
||||||
@signals.init_schema.connect
|
@signals.init_schema.connect
|
||||||
def add_types_to_schema(schema):
|
def add_types_to_schema(schema):
|
||||||
own_schema = schema
|
own_schema = schema
|
||||||
|
|
|
@ -14,9 +14,7 @@ class Ship(relay.Node):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_node(cls, id):
|
def get_node(cls, id):
|
||||||
ship = getShip(id)
|
return Ship(getShip(id))
|
||||||
if ship:
|
|
||||||
return Ship(ship)
|
|
||||||
|
|
||||||
|
|
||||||
class Faction(relay.Node):
|
class Faction(relay.Node):
|
||||||
|
@ -30,9 +28,7 @@ class Faction(relay.Node):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_node(cls, id):
|
def get_node(cls, id):
|
||||||
faction = getFaction(id)
|
return Faction(getFaction(id))
|
||||||
if faction:
|
|
||||||
return Faction(faction)
|
|
||||||
|
|
||||||
|
|
||||||
class Query(graphene.ObjectType):
|
class Query(graphene.ObjectType):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user