Skip to content

Commit

Permalink
Added execution context example. Fixed #306
Browse files Browse the repository at this point in the history
  • Loading branch information
syrusakbary committed Nov 15, 2016
1 parent bb7976a commit cc776e8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -223,3 +223,7 @@ dummy:
$(SPHINXBUILD) -b dummy $(ALLSPHINXOPTS) $(BUILDDIR)/dummy
@echo
@echo "Build finished. Dummy builder generates no files."

.PHONY: livehtml
livehtml:
sphinx-autobuild -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
32 changes: 32 additions & 0 deletions docs/execution/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,38 @@
Execution
=========

For executing a query a schema, you can directly call the ``execute`` method on it.


.. code:: python
schema = graphene.Schema(...)
result = schema.execute('{ name }')
``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.


Context
_______

You can pass context to a query via ``context_value``.


.. code:: python
class Query(graphene.ObjectType):
name = graphene.String()
def resolve_name(self, args, context, info):
return context.get('name')
schema = graphene.Schema(Query)
result = schema.execute('{ name }', context_value={'name': 'Syrus'})
Middleware
__________

.. toctree::
:maxdepth: 1

Expand Down

0 comments on commit cc776e8

Please sign in to comment.