strawberry.relay.connection

Annotate a property or a method to create a relay connection field.

Relay connections are mostly used for pagination purposes. This decorator helps creating a complete relay endpoint that provides default arguments and has a default implementation for the connection slicing.

Note that when setting a resolver to this field, it is expected for this resolver to return an iterable of the expected node type, not the connection itself. That iterable will then be paginated accordingly. So, the main use case for this is to provide a filtered iterable of nodes by using some custom filter arguments.

Signature:

def connection(
graphql_type: Type[Connection[NodeType]] | None = None,
resolver: _RESOLVER_TYPE[Any] | None = None,
name: str | None = None,
is_subscription: bool = False,
description: str | None = None,
permission_classes: List[Type[BasePermission]] | None = None,
deprecation_reason: str | None = None,
default: Any = dataclasses.MISSING,
default_factory: Callable[..., object] | object = dataclasses.MISSING,
metadata: Mapping[Any, Any] | None = None,
directives: Sequence[object] | None = (),
extensions: List[FieldExtension] = (),
init: Literal[True, False, None] = None,
) -> Any:
...

Parameters:

  1. graphql_type:

    The type of the nodes in the connection. This is used to determine the type of the edges and the node field in the connection.

    Type
    Type[Connection[NodeType]] | None
    Default
    None
  2. resolver:

    The resolver for the connection. This is expected to return an iterable of the expected node type.

    Type
    _RESOLVER_TYPE[Any] | None
    Default
    None
  3. name:

    The GraphQL name of the field.

    Type
    str | None
    Default
    None
  4. is_subscription:

    Whether the field is a subscription.

    Type
    bool
    Default
    False
  5. description:

    The GraphQL description of the field.

    Type
    str | None
    Default
    None
  6. permission_classes:

    The permission classes to apply to the field.

    Type
    List[Type[BasePermission]] | None
    Default
    None
  7. deprecation_reason:

    The deprecation reason of the field.

    Type
    str | None
    Default
    None
  8. default:

    The default value of the field.

    Type
    Any
    Default
    dataclasses.MISSING
  9. default_factory:

    The default factory of the field.

    Type
    Callable[..., object] | object
    Default
    dataclasses.MISSING
  10. metadata:

    The metadata of the field.

    Type
    Mapping[Any, Any] | None
    Default
    None
  11. directives:

    The directives to apply to the field.

    Type
    Sequence[object] | None
    Default
    ()
  12. extensions:

    The extensions to apply to the field.

    Type
    List[FieldExtension]
    Default
    ()
  13. init:

    Used only for type checking purposes.

    Type
    Literal[True, False, None]
    Default
    None