Skip to content

Commit cc776e8

Browse files
committed
Added execution context example. Fixed #306
1 parent bb7976a commit cc776e8

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

docs/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,3 +223,7 @@ dummy:
223223
$(SPHINXBUILD) -b dummy $(ALLSPHINXOPTS) $(BUILDDIR)/dummy
224224
@echo
225225
@echo "Build finished. Dummy builder generates no files."
226+
227+
.PHONY: livehtml
228+
livehtml:
229+
sphinx-autobuild -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html

docs/execution/index.rst

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,38 @@
22
Execution
33
=========
44

5+
For executing a query a schema, you can directly call the ``execute`` method on it.
6+
7+
8+
.. code:: python
9+
10+
schema = graphene.Schema(...)
11+
result = schema.execute('{ name }')
12+
13+
``result`` represents he result of execution. ``result.data`` is the result of executing the query, ``result.errors`` is ``None`` if no errors occurred, and is a non-empty list if an error occurred.
14+
15+
16+
Context
17+
_______
18+
19+
You can pass context to a query via ``context_value``.
20+
21+
22+
.. code:: python
23+
24+
class Query(graphene.ObjectType):
25+
name = graphene.String()
26+
27+
def resolve_name(self, args, context, info):
28+
return context.get('name')
29+
30+
schema = graphene.Schema(Query)
31+
result = schema.execute('{ name }', context_value={'name': 'Syrus'})
32+
33+
34+
Middleware
35+
__________
36+
537
.. toctree::
638
:maxdepth: 1
739

0 commit comments

Comments
 (0)