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
|
||||
def resolve_human(self, id):
|
||||
return wrap_character(getHuman(id))
|
||||
if human:
|
||||
return Human(human)
|
||||
|
||||
@resolve_only_args
|
||||
def resolve_droid(self, id):
|
||||
|
@ -91,9 +89,7 @@ class Ship(relay.Node):
|
|||
|
||||
@classmethod
|
||||
def get_node(cls, id):
|
||||
ship = getShip(id)
|
||||
if ship:
|
||||
return Ship(ship)
|
||||
return Ship(getShip(id))
|
||||
|
||||
|
||||
class Faction(relay.Node):
|
||||
|
@ -107,9 +103,7 @@ class Faction(relay.Node):
|
|||
|
||||
@classmethod
|
||||
def get_node(cls, id):
|
||||
faction = getFaction(id)
|
||||
if faction:
|
||||
return Faction(faction)
|
||||
return Faction(getFaction(id)
|
||||
|
||||
|
||||
class Query(graphene.ObjectType):
|
||||
|
|
|
@ -43,10 +43,11 @@ class Schema(object):
|
|||
return self._types[type_name]
|
||||
|
||||
def execute(self, request='', root=None, vars=None, operation_name=None):
|
||||
root = root or object()
|
||||
return graphql(
|
||||
self._schema,
|
||||
request=request,
|
||||
root=root or self.query(),
|
||||
root=self.query(root),
|
||||
vars=vars,
|
||||
operation_name=operation_name
|
||||
)
|
||||
|
|
|
@ -83,6 +83,13 @@ class ObjectTypeMeta(type):
|
|||
|
||||
|
||||
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):
|
||||
signals.pre_init.send(self.__class__, instance=instance)
|
||||
self.instance = instance
|
||||
|
@ -136,6 +143,7 @@ class Interface(ObjectType):
|
|||
interface = True
|
||||
proxy = True
|
||||
|
||||
|
||||
@signals.init_schema.connect
|
||||
def add_types_to_schema(schema):
|
||||
own_schema = schema
|
||||
|
|
|
@ -14,9 +14,7 @@ class Ship(relay.Node):
|
|||
|
||||
@classmethod
|
||||
def get_node(cls, id):
|
||||
ship = getShip(id)
|
||||
if ship:
|
||||
return Ship(ship)
|
||||
return Ship(getShip(id))
|
||||
|
||||
|
||||
class Faction(relay.Node):
|
||||
|
@ -30,9 +28,7 @@ class Faction(relay.Node):
|
|||
|
||||
@classmethod
|
||||
def get_node(cls, id):
|
||||
faction = getFaction(id)
|
||||
if faction:
|
||||
return Faction(faction)
|
||||
return Faction(getFaction(id))
|
||||
|
||||
|
||||
class Query(graphene.ObjectType):
|
||||
|
|
Loading…
Reference in New Issue
Block a user