Skip to content

Commit adfbffb

Browse files
committed
Added middleware docs
1 parent 9a3d843 commit adfbffb

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

docs/execution/index.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
=========
2+
Execution
3+
=========
4+
5+
.. toctree::
6+
:maxdepth: 1
7+
8+
middleware

docs/execution/middleware.rst

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
Middleware
2+
==========
3+
4+
You can use ``middleware`` to affect the evaluation of fields in your schema.
5+
6+
A middleware is any object that responds to ``resolve(*args, next_middleware)``.
7+
8+
Inside that method, it should either:
9+
10+
- Send ``resolve`` to the next middleware to continue the evaluation; or
11+
- Return a value to end the evaluation early.
12+
13+
14+
Resolve arguments
15+
-----------------
16+
17+
Middlewares ``resolve`` is invoked with several arguments:
18+
19+
- ``next`` represents the execution chain. Call ``next`` to continue evalution.
20+
- ``root`` is the root value object passed throughout the query.
21+
- ``args`` is the hash of arguments passed to the field.
22+
- ``context`` is the context object passed throughout the query.
23+
- ``info`` is the resolver info.
24+
25+
26+
Example
27+
-------
28+
29+
This middleware only continues evaluation if the ``field_name`` is not ``'user'``
30+
31+
.. code:: python
32+
33+
class AuthorizationMiddleware(object):
34+
def resolve(self, next, root, args, context, info):
35+
if info.field_name == 'user':
36+
return None
37+
return next(root, args, context, info)
38+
39+
40+
And then execute it with:
41+
42+
.. code:: python
43+
44+
result = schema.execute('THE QUERY', middleware=[AuthorizationMiddleware()])

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Contents:
88

99
quickstart
1010
types/index
11+
execution/index
1112
relay/index
1213

1314
Integrations

0 commit comments

Comments
 (0)