mirror of
https://github.com/graphql-python/graphene.git
synced 2025-02-02 12:44:15 +03:00
Improved django example
This commit is contained in:
parent
0a395fec58
commit
d13d7c0f68
|
@ -12,7 +12,6 @@ schema = graphene.Schema(name='Starwars Django Relay Schema')
|
||||||
|
|
||||||
|
|
||||||
class Ship(DjangoNode):
|
class Ship(DjangoNode):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = ShipModel
|
model = ShipModel
|
||||||
|
|
||||||
|
@ -21,15 +20,12 @@ class Ship(DjangoNode):
|
||||||
return Ship(get_ship(id))
|
return Ship(get_ship(id))
|
||||||
|
|
||||||
|
|
||||||
@schema.register
|
|
||||||
class Character(DjangoObjectType):
|
class Character(DjangoObjectType):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = CharacterModel
|
model = CharacterModel
|
||||||
|
|
||||||
|
|
||||||
class Faction(DjangoNode):
|
class Faction(DjangoNode):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = FactionModel
|
model = FactionModel
|
||||||
|
|
||||||
|
@ -39,7 +35,6 @@ class Faction(DjangoNode):
|
||||||
|
|
||||||
|
|
||||||
class IntroduceShip(relay.ClientIDMutation):
|
class IntroduceShip(relay.ClientIDMutation):
|
||||||
|
|
||||||
class Input:
|
class Input:
|
||||||
ship_name = graphene.StringField(required=True)
|
ship_name = graphene.StringField(required=True)
|
||||||
faction_id = graphene.StringField(required=True)
|
faction_id = graphene.StringField(required=True)
|
||||||
|
@ -79,5 +74,9 @@ class Mutation(graphene.ObjectType):
|
||||||
introduce_ship = graphene.Field(IntroduceShip)
|
introduce_ship = graphene.Field(IntroduceShip)
|
||||||
|
|
||||||
|
|
||||||
|
# We register the Character Model because if not would be
|
||||||
|
# inaccessible for the schema
|
||||||
|
schema.register(Character)
|
||||||
|
|
||||||
schema.query = Query
|
schema.query = Query
|
||||||
schema.mutation = Mutation
|
schema.mutation = Mutation
|
||||||
|
|
Loading…
Reference in New Issue
Block a user