mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-11 12:16:58 +03:00
Merge pull request #502 from Thibaut-Fatus/patch-1
Doc was missing for using variables in queries
This commit is contained in:
commit
557ec44a13
|
@ -30,3 +30,30 @@ You can pass context to a query via ``context_value``.
|
|||
schema = graphene.Schema(Query)
|
||||
result = schema.execute('{ name }', context_value={'name': 'Syrus'})
|
||||
|
||||
|
||||
|
||||
Variables
|
||||
_______
|
||||
|
||||
You can pass variables to a query via ``variable_values``.
|
||||
|
||||
|
||||
.. code:: python
|
||||
|
||||
class Query(graphene.ObjectType):
|
||||
user = graphene.Field(User)
|
||||
|
||||
def resolve_user(self, args, context, info):
|
||||
return context.get('user')
|
||||
|
||||
schema = graphene.Schema(Query)
|
||||
result = schema.execute(
|
||||
'''query getUser($id: ID) {
|
||||
user(id: $id) {
|
||||
id
|
||||
firstName
|
||||
lastName
|
||||
}
|
||||
}''',
|
||||
variable_values={'id': 12},
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue
Block a user