Skip to content

Commit 557ec44

Browse files
authored
Merge pull request #502 from Thibaut-Fatus/patch-1
Doc was missing for using variables in queries
2 parents 3e62fcf + c155b7a commit 557ec44

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

docs/execution/execute.rst

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,30 @@ You can pass context to a query via ``context_value``.
3030
schema = graphene.Schema(Query)
3131
result = schema.execute('{ name }', context_value={'name': 'Syrus'})
3232
33+
34+
35+
Variables
36+
_______
37+
38+
You can pass variables to a query via ``variable_values``.
39+
40+
41+
.. code:: python
42+
43+
class Query(graphene.ObjectType):
44+
user = graphene.Field(User)
45+
46+
def resolve_user(self, args, context, info):
47+
return context.get('user')
48+
49+
schema = graphene.Schema(Query)
50+
result = schema.execute(
51+
'''query getUser($id: ID) {
52+
user(id: $id) {
53+
id
54+
firstName
55+
lastName
56+
}
57+
}''',
58+
variable_values={'id': 12},
59+
)

0 commit comments

Comments
 (0)