forked from dvndrsn/graphql-python-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauthor.py
More file actions
51 lines (37 loc) · 1.95 KB
/
author.py
File metadata and controls
51 lines (37 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from typing import Any, List, Iterable, Optional # pylint: disable=unused-import
import graphene
from story import models
class AuthorDisplayNameEnum(graphene.Enum):
FIRST_LAST = models.Author.DISPLAY_FIRST_LAST
LAST_FIRST = models.Author.DISPLAY_LAST_FIRST
class AuthorType(graphene.ObjectType):
# Exercise 4!
# Let's evolve the schema to include an AuthorType and AuthorConnection!
# - run `invoke test` to verify the changes using a test case
# - run `invoke start` to run queries against `localhost:8000/graphql`
# - sample queries available in `api/queries.graphql`
# The `models.Author` object has the following attributes to use to resolve our new fields:
# - id - ID
# - String - first_name, last_name, twitter_account
# - function for formatting names - full_name(display) -> str
# Remember:
# - Refer to `api/query/story.py` for examples of similar implementation.
# - REFERENCE.md may be helpful to brush up on Django ORM as well!
# - Graphene auto-camelCases fields from our Python code!
# AuthorType schema changes:
# - Ensure AuthorType has the following String fields in the GraphQL schema:
# - id, firstName, lastName, twitterAccount, fullName
# - AuthorType should implement the Node Interface (as StoryType does)
dummy = graphene.String(description='Enter your stuff here')
# AuthorType resovler changes:
# - AuthorType.fullName field should have similar implementation as StoryType.fullName
# - AuthorType should implement `get_node` to fetch a single Author from the ORM
# - AuthorType should implement `is_type_of` to disambiguate inline fragments in our queries
# Add a new type:
# - Implement AuthorConnection with AuthorType as node
class Query(graphene.ObjectType):
# Query schema changes:
# - Add Query.authors connection field to paginate over authors
node = graphene.Node.Field()
# Query resolver changes:
# - Add a resolver for authors