From c417a56998fc92a15c5f6d89485a8bfba2b63220 Mon Sep 17 00:00:00 2001 From: zhammer Date: Sun, 16 Dec 2018 10:28:23 -0500 Subject: [PATCH 1/2] Make top-level module docstring runnable, doctest code --- front/delivery/graphql/schema.py | 54 +++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 19 deletions(-) diff --git a/front/delivery/graphql/schema.py b/front/delivery/graphql/schema.py index ea99392..4db2b8e 100644 --- a/front/delivery/graphql/schema.py +++ b/front/delivery/graphql/schema.py @@ -3,25 +3,41 @@ This isn't super intuitive and at the moment is not very well documented. We can have something like: -```py -class PersonNamedTuple(NamedTuple): - first_name: str - last_name: str - -class PersonGraphQl(graphene.ObjectType): - first_name: graphene.String() - last_name: graphene.String() - full_name: graphene.String() - - def resolve_full_name(root: PersonNamedTuple) -> str: # root is a PersonNamedTuple. - return self.first_name + ' ' + self.last_name - -class Query(graphene.ObjectType): - person = graphene.Field(PersonGraphQl) # `person` is a PersonGraphQl type. - - def resolve_person(root) -> PersonNamedTuple: # But its resolver returns a PersonNamedTuple. - return PersonNamedTuple('Michael', 'Jackson') -``` +>>> import json +>>> from typing import NamedTuple +>>> import graphene +>>> +>>> class PersonNamedTuple(NamedTuple): +... first_name: str +... last_name: str +>>> +>>> class PersonGraphQl(graphene.ObjectType): +... first_name = graphene.String() +... last_name = graphene.String() +... full_name = graphene.String() +... +... def resolve_full_name(root: PersonNamedTuple, info) -> str: # root is a PersonNamedTuple. +... return root.first_name + ' ' + root.last_name +>>> +>>> class Query(graphene.ObjectType): +... person = graphene.Field(PersonGraphQl) # `person` is a PersonGraphQl type. +... +... # But its resolver returns a PersonNamedTuple. +... def resolve_person(root, info) -> PersonNamedTuple: +... return PersonNamedTuple('Michael', 'Jackson') +>>> +>>> result = graphene.Schema(query=Query).execute(''' +... query person { +... person { +... firstName +... lastName +... fullName +... } +... } +... ''') +>>> +>>> print(json.dumps(result.data)) +{"person": {"firstName": "Michael", "lastName": "Jackson", "fullName": "Michael Jackson"}} It's a little funky, and even funkier for the relay pagination stuff. From 38f8936bf1cba6144453b5d8034fb9c91f9cf9e4 Mon Sep 17 00:00:00 2001 From: zhammer Date: Sun, 16 Dec 2018 10:31:04 -0500 Subject: [PATCH 2/2] Update language around music providers At the moment the language is: - spotify is a music provider - each listen has a 'song provider' field, which is a music provider type --- front/delivery/graphql/schema.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/front/delivery/graphql/schema.py b/front/delivery/graphql/schema.py index 4db2b8e..1501539 100644 --- a/front/delivery/graphql/schema.py +++ b/front/delivery/graphql/schema.py @@ -67,7 +67,7 @@ class Meta: id = graphene.ID(required=True) name = graphene.String() - vendor = GraphQlMusicProvider() + song_provider = GraphQlMusicProvider() artist_name = graphene.String() album_name = graphene.String() image_large_url = graphene.String() @@ -204,7 +204,7 @@ class Meta: name = 'ListenInput' song_id = graphene.String(required=True) - music_provider = GraphQlMusicProvider(default_value=GraphQlMusicProvider.SPOTIFY.value) + song_provider = GraphQlMusicProvider(default_value=GraphQlMusicProvider.SPOTIFY.value) listener_name = graphene.String(required=True) note = graphene.String(required=False) iana_timezone = graphene.String(required=True) @@ -220,7 +220,7 @@ class Arguments: def mutate(root, info: ResolveInfo, input: GraphQlListenInput) -> Listen: listen = ListenInput( song_id=input.song_id, - song_provider=MusicProvider(input.music_provider), + song_provider=MusicProvider(input.song_provider), listener_name=input.listener_name, note=input.note, iana_timezone=input.iana_timezone