Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
57 changed files
with
1,187 additions
and
183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
========= | ||
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 | ||
|
||
middleware |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
Middleware | ||
========== | ||
|
||
You can use ``middleware`` to affect the evaluation of fields in your schema. | ||
|
||
A middleware is any object that responds to ``resolve(*args, next_middleware)``. | ||
|
||
Inside that method, it should either: | ||
|
||
- Send ``resolve`` to the next middleware to continue the evaluation; or | ||
- Return a value to end the evaluation early. | ||
|
||
|
||
Resolve arguments | ||
----------------- | ||
|
||
Middlewares ``resolve`` is invoked with several arguments: | ||
|
||
- ``next`` represents the execution chain. Call ``next`` to continue evalution. | ||
- ``root`` is the root value object passed throughout the query. | ||
- ``args`` is the hash of arguments passed to the field. | ||
- ``context`` is the context object passed throughout the query. | ||
- ``info`` is the resolver info. | ||
|
||
|
||
Example | ||
------- | ||
|
||
This middleware only continues evaluation if the ``field_name`` is not ``'user'`` | ||
|
||
.. code:: python | ||
class AuthorizationMiddleware(object): | ||
def resolve(self, next, root, args, context, info): | ||
if info.field_name == 'user': | ||
return None | ||
return next(root, args, context, info) | ||
And then execute it with: | ||
|
||
.. code:: python | ||
result = schema.execute('THE QUERY', middleware=[AuthorizationMiddleware()]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ Contents: | |
|
||
quickstart | ||
types/index | ||
execution/index | ||
relay/index | ||
|
||
Integrations | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.