mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-23 01:56:54 +03:00
5cb7d91aaa
* Revise documentation - Add missing reference to `flask-graphql` in integrations - align documentation for resolver arguments (use root for 1st argument instead of self) - explore use of `parent` instead of `root` for first argument - clarify resolvers and object type documentation - add documentation for Meta class options for ObjectType - expand quickstart documentation for first time users - streamline order of documentation for first time users (broad -> specific) - document resolver quirks * explict imports from graphene * rename doc refs for resolvers * suggestions typos and graphene import
46 lines
1.3 KiB
ReStructuredText
46 lines
1.3 KiB
ReStructuredText
Connection
|
|
==========
|
|
|
|
A connection is a vitaminized version of a List that provides ways of
|
|
slicing and paginating through it. The way you create Connection types
|
|
in ``graphene`` is using ``relay.Connection`` and ``relay.ConnectionField``.
|
|
|
|
Quick example
|
|
-------------
|
|
|
|
If we want to create a custom Connection on a given node, we have to subclass the
|
|
``Connection`` class.
|
|
|
|
In the following example, ``extra`` will be an extra field in the connection,
|
|
and ``other`` an extra field in the Connection Edge.
|
|
|
|
.. code:: python
|
|
|
|
class ShipConnection(Connection):
|
|
extra = String()
|
|
|
|
class Meta:
|
|
node = Ship
|
|
|
|
class Edge:
|
|
other = String()
|
|
|
|
The ``ShipConnection`` connection class, will have automatically a ``pageInfo`` field,
|
|
and a ``edges`` field (which is a list of ``ShipConnection.Edge``).
|
|
This ``Edge`` will have a ``node`` field linking to the specified node
|
|
(in ``ShipConnection.Meta``) and the field ``other`` that we defined in the class.
|
|
|
|
Connection Field
|
|
----------------
|
|
You can create connection fields in any Connection, in case any ObjectType
|
|
that implements ``Node`` will have a default Connection.
|
|
|
|
.. code:: python
|
|
|
|
class Faction(graphene.ObjectType):
|
|
name = graphene.String()
|
|
ships = relay.ConnectionField(ShipConnection)
|
|
|
|
def resolve_ships(root, info):
|
|
return []
|