-
Notifications
You must be signed in to change notification settings - Fork 819
Open
Labels
Description
The Root Value example in the documentation:
from graphene import ObjectType, Field, Schema
class Query(ObjectType):
me = Field(User)
def resolve_user(root, info):
return {'id': root.id, 'firstName': root.name}
schema = Schema(Query)
user_root = User(id=12, name='bob')
result = schema.execute(
'''
query getUser {
user {
id
firstName
lastName
}
}
''',
root=user_root
)
assert result.data['user']['id'] == user_root.id
doesn't work. Throws NameError: name 'User' is not defined.
What's not clear is:
- Where
Useris defined -- is it defined somewhere else in the documentation? (hyperlink/inline) - The
Queryfield is namedmeyet the resolver function is namedresolve_user. - The executed query asks for
user(notme). - The created
Userobject (assigned touser_root) is constructed to have anamefield, yet the query asks for thefirstNameandlastNamefields. Sure,resolve_userreturns a dict withid, andfirstName, but this adds to the confusion.
Having various combinations of name, firstName and lastName is confusing, especially in an example that doesn't work.