mirror of
https://github.com/graphql-python/graphene.git
synced 2025-02-02 12:44:15 +03:00
Root Value example doesn't work #1303
This commit is contained in:
parent
2e87ebe5fc
commit
caf6e506a5
|
@ -76,13 +76,22 @@ Value used for :ref:`ResolverParamParent` in root queries and mutations can be o
|
||||||
|
|
||||||
.. code:: python
|
.. code:: python
|
||||||
|
|
||||||
from graphene import ObjectType, Field, Schema
|
from graphene import ObjectType, Field, Schema, String, ID
|
||||||
|
|
||||||
|
|
||||||
|
class User(ObjectType):
|
||||||
|
id = ID()
|
||||||
|
name = String()
|
||||||
|
first_name = String()
|
||||||
|
last_name = String()
|
||||||
|
|
||||||
|
|
||||||
class Query(ObjectType):
|
class Query(ObjectType):
|
||||||
me = Field(User)
|
user = Field(User)
|
||||||
|
|
||||||
def resolve_user(root, info):
|
def resolve_user(root, info):
|
||||||
return {'id': root.id, 'firstName': root.name}
|
return User(id=root.id, first_name=root.name)
|
||||||
|
|
||||||
|
|
||||||
schema = Schema(Query)
|
schema = Schema(Query)
|
||||||
user_root = User(id=12, name='bob')
|
user_root = User(id=12, name='bob')
|
||||||
|
@ -98,7 +107,8 @@ Value used for :ref:`ResolverParamParent` in root queries and mutations can be o
|
||||||
''',
|
''',
|
||||||
root=user_root
|
root=user_root
|
||||||
)
|
)
|
||||||
assert result.data['user']['id'] == user_root.id
|
assert result.data['user']['id'] == str(user_root.id)
|
||||||
|
|
||||||
|
|
||||||
Operation Name
|
Operation Name
|
||||||
______________
|
______________
|
||||||
|
|
Loading…
Reference in New Issue
Block a user