Created
May 10, 2020 10:34
-
-
Save ksdme/ba8c7c65cbc621eff0e8da95d1abaf4d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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