Skip to content

Instantly share code, notes, and snippets.

@ksdme
Created May 10, 2020 10:34
Show Gist options
  • Save ksdme/ba8c7c65cbc621eff0e8da95d1abaf4d to your computer and use it in GitHub Desktop.
Save ksdme/ba8c7c65cbc621eff0e8da95d1abaf4d to your computer and use it in GitHub Desktop.
import graphene
venues = {
'0': 'Big Hotel',
'1': 'Small Hotel',
}
class Venue(graphene.ObjectType):
address = graphene.String()
class Event(graphene.ObjectType):
id = graphene.String()
host = graphene.String()
venue = graphene.Field(Venue)
def resolve_venue(self, *a, **k):
return Venue(address=venues.get(self.venue))
class Query(graphene.ObjectType):
events = graphene.List(Event)
def resolve_events(self, info, *args, **kwargs):
ql_events = []
for sample in range(10):
ql_events.append(Event(
id=str(sample),
host=str(sample),
venue=str(sample % 2),
))
return ql_events
schema = graphene.Schema(query=Query)
result = schema.execute('query { events { id, host, venue { address } } }')
print(result.data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment