mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-22 09:36:44 +03:00
Merge branch 'master' into features/extra-resolvers
This commit is contained in:
commit
7b26e8d458
|
@ -3,7 +3,7 @@ Nodes
|
||||||
|
|
||||||
A ``Node`` is an Interface provided by ``graphene.relay`` that contains
|
A ``Node`` is an Interface provided by ``graphene.relay`` that contains
|
||||||
a single field ``id`` (which is a ``ID!``). Any object that inherits
|
a single field ``id`` (which is a ``ID!``). Any object that inherits
|
||||||
from it have to implement a ``get_node`` method for retrieving a
|
from it has to implement a ``get_node`` method for retrieving a
|
||||||
``Node`` by an *id*.
|
``Node`` by an *id*.
|
||||||
|
|
||||||
|
|
||||||
|
@ -26,8 +26,8 @@ Example usage (taken from the `Starwars Relay example`_):
|
||||||
return get_ship(id)
|
return get_ship(id)
|
||||||
|
|
||||||
The ``id`` returned by the ``Ship`` type when you query it will be a
|
The ``id`` returned by the ``Ship`` type when you query it will be a
|
||||||
scalar which contains the enough info for the server for knowing it’s
|
scalar which contains enough info for the server to know its type and
|
||||||
type and it’s id.
|
its id.
|
||||||
|
|
||||||
For example, the instance ``Ship(id=1)`` will return ``U2hpcDox`` as the
|
For example, the instance ``Ship(id=1)`` will return ``U2hpcDox`` as the
|
||||||
id when you query it (which is the base64 encoding of ``Ship:1``), and
|
id when you query it (which is the base64 encoding of ``Ship:1``), and
|
||||||
|
@ -77,7 +77,7 @@ Accessing node types
|
||||||
If we want to retrieve node instances from a ``global_id`` (scalar that identifies an instance by it's type name and id),
|
If we want to retrieve node instances from a ``global_id`` (scalar that identifies an instance by it's type name and id),
|
||||||
we can simply do ``Node.get_node_from_global_id(global_id, context, info)``.
|
we can simply do ``Node.get_node_from_global_id(global_id, context, info)``.
|
||||||
|
|
||||||
In the case we want to restrict the instnance retrieval to an specific type, we can do:
|
In the case we want to restrict the instance retrieval to a specific type, we can do:
|
||||||
``Node.get_node_from_global_id(global_id, context, info, only_type=Ship)``. This will raise an error
|
``Node.get_node_from_global_id(global_id, context, info, only_type=Ship)``. This will raise an error
|
||||||
if the ``global_id`` doesn't correspond to a Ship type.
|
if the ``global_id`` doesn't correspond to a Ship type.
|
||||||
|
|
||||||
|
|
|
@ -1,2 +1,4 @@
|
||||||
|
# Required library
|
||||||
|
Sphinx==1.5.3
|
||||||
# Docs template
|
# Docs template
|
||||||
https://github.com/graphql-python/graphene-python.org/archive/docs.zip
|
https://github.com/graphql-python/graphene-python.org/archive/docs.zip
|
||||||
|
|
|
@ -10,20 +10,20 @@ This example defines a Mutation:
|
||||||
|
|
||||||
.. code:: python
|
.. code:: python
|
||||||
|
|
||||||
import graphene
|
import graphene
|
||||||
|
|
||||||
class CreatePerson(graphene.Mutation):
|
class CreatePerson(graphene.Mutation):
|
||||||
class Input:
|
class Input:
|
||||||
name = graphene.String()
|
name = graphene.String()
|
||||||
|
|
||||||
ok = graphene.Boolean()
|
ok = graphene.Boolean()
|
||||||
person = graphene.Field(lambda: Person)
|
person = graphene.Field(lambda: Person)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def mutate(root, args, context, info):
|
def mutate(root, args, context, info):
|
||||||
person = Person(name=args.get('name'))
|
person = Person(name=args.get('name'))
|
||||||
ok = True
|
ok = True
|
||||||
return CreatePerson(person=person, ok=ok)
|
return CreatePerson(person=person, ok=ok)
|
||||||
|
|
||||||
**person** and **ok** are the output fields of the Mutation when is
|
**person** and **ok** are the output fields of the Mutation when is
|
||||||
resolved.
|
resolved.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user