Skip to content

Instantly share code, notes, and snippets.

@salwator
Last active April 29, 2019 07:48
Show Gist options
  • Save salwator/80cace8a207902a1a53397a5bca2a821 to your computer and use it in GitHub Desktop.
Save salwator/80cace8a207902a1a53397a5bca2a821 to your computer and use it in GitHub Desktop.
GoT in Graphene
import graphene
class House(graphene.ObjectType):
name = graphene.String(required=True)
castle = graphene.String(required=True)
members = graphene.List(graphene.NonNull(lambda: Person))
class Person(graphene.ObjectType):
name = graphene.String(required=True)
house = graphene.Field(House)
parents = graphene.List(graphene.NonNull(lambda: Person))
is_alive = graphene.Boolean()
class Kingdom(graphene.ObjectType):
name = graphene.String(required=True)
castle = graphene.String(required=True)
members = graphene.List(graphene.NonNull(Person))
class Query(graphene.ObjectType):
kingdoms = graphene.NonNull(graphene.List(graphene.NonNull(Kingdom)))
def resolve_kingdoms(self, info):
house_of_stark = {"name": "Stark", "castle": "Winterfell"}
king_in_the_north = {
"name": "Jon Snow",
"house": house_of_stark,
"is_alive": True,
}
return [{"name": "The North", "ruler": king_in_the_north}]
schema = graphene.Schema(query=Query)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment