Skip to content

Instantly share code, notes, and snippets.

@salwator
Last active April 29, 2019 07:48
Show Gist options
  • Save salwator/4ee217ac0d6118818866912d3fc6dbf9 to your computer and use it in GitHub Desktop.
Save salwator/4ee217ac0d6118818866912d3fc6dbf9 to your computer and use it in GitHub Desktop.
GoT in Ariadne
from ariadne import ObjectType, QueryType, gql, make_executable_schema
from ariadne.asgi import GraphQL
type_defs = gql(
"""
type Person {
name: String
house: House
parents: [Person!]
isAlive: Boolean
}
type House {
name: String!
castle: String!
members: [Person!]
}
type Kingdom {
ruler: Person
kings: [Person!]
}
type Query {
kingdoms: [Kingdom!]!
}
"""
)
query = QueryType()
@query.field("kingdoms")
def resolve_kingdoms(*_):
# this is where you would want to fetch and filter data you want
house_of_stark = {"name": "Stark", "castle": "Winterfell"}
king_in_the_north = {"name": "Jon Snow", "house": house_of_stark, "isAlive": True}
return [{"ruler": king_in_the_north}]
schema = make_executable_schema(type_defs, [query])
app = GraphQL(schema)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment