GitHub

operation

API reference for operation.

GraphQL operations (Effect's GraphQL): a document with a variables schema and a result schema, as @effect/graphql-generator emits them.

query / mutation give an Operation, subscription a Subscription. Put operations on a GraphQLGroup class; read on the client client.make(Group) gives, an operation is its method::

Viewer = query("Viewer", document="query Viewer{viewer{login}}", result=VIEWER)

class Api(GraphQLGroup):
    viewer = Viewer

api = yield* client.make(Api)
result = yield* api.viewer()

Operation[V, A, ME_co, MR_co]: variables V, result A, middleware errors ME_co, and the services its schemas and middleware need MR_co.

Values

AttributeTypeDescription
NO_VARIABLESStructSchema[NoVariables, Never, Never]

Types

TypeDefinitionDescription
Calltype Call = Callable[[object, CallOptions], Any]
AnyOperationtype AnyOperation = OperationInfo

Classes

Functions

query

query[A, V = NoVariables, RR = Never](name, *, document, result, variables=None) -> Operation[V, A, Never, RR]

A query: its document (or the template it is joined from), the result schema of its data and, when it declares variables, their schema.

ParameterTypeDescription
namestr
documentstr | DocumentTemplate
resultCodec[A, Any, RR, Any]
variablesCodec[V, Any, Any, RR] | None = None

Returns Operation[V, A, Never, RR]

def query[A, V = NoVariables, RR = Never](
    name: str,
    *,
    document: str | DocumentTemplate,
    result: Codec[A, Any, RR, Any],
    variables: Codec[V, Any, Any, RR] | None = None,
) -> Operation[V, A, Never, RR]:
    """A query: its ``document`` (or the template it is joined from), the
    ``result`` schema of its ``data`` and, when it declares variables, their
    schema."""
    return Operation(**_fields("query", name, document, variables, result))

mutation

mutation[A, V = NoVariables, RR = Never](name, *, document, result, variables=None) -> Operation[V, A, Never, RR]

A mutation; see query.

ParameterTypeDescription
namestr
documentstr | DocumentTemplate
resultCodec[A, Any, RR, Any]
variablesCodec[V, Any, Any, RR] | None = None

Returns Operation[V, A, Never, RR]

def mutation[A, V = NoVariables, RR = Never](
    name: str,
    *,
    document: str | DocumentTemplate,
    result: Codec[A, Any, RR, Any],
    variables: Codec[V, Any, Any, RR] | None = None,
) -> Operation[V, A, Never, RR]:
    """A mutation; see ``query``."""
    return Operation(**_fields("mutation", name, document, variables, result))

subscription

subscription[A, V = NoVariables, RR = Never](name, *, document, result, variables=None) -> Subscription[V, A, Never, RR]

A subscription; see query.

ParameterTypeDescription
namestr
documentstr | DocumentTemplate
resultCodec[A, Any, RR, Any]
variablesCodec[V, Any, Any, RR] | None = None

Returns Subscription[V, A, Never, RR]

def subscription[A, V = NoVariables, RR = Never](
    name: str,
    *,
    document: str | DocumentTemplate,
    result: Codec[A, Any, RR, Any],
    variables: Codec[V, Any, Any, RR] | None = None,
) -> Subscription[V, A, Never, RR]:
    """A subscription; see ``query``."""
    return Subscription(**_fields("subscription", name, document, variables, result))

other_typename

other_typename(selected) -> S.Bottom[str]

The __typename of a union member the document did not select: any string but the selected names, including names the server adds later.

ParameterTypeDescription
selectedSequence[str]

Returns S.Bottom[str]

def other_typename(selected: Sequence[str], /) -> S.Bottom[str]:
    """The ``__typename`` of a union member the document did not select:
    any string but the ``selected`` names, including names the server adds
    later."""
    rejected = frozenset(selected)
    names = ", ".join(f'"{name}"' for name in selected)

    def other(name: str) -> TypeIs[str]:
        return name not in rejected

    return S.String.pipe(
        S.refine(other, title="otherTypename", expected=f"a __typename other than {names}")
    )

enum_literals

enum_literals[L: str](literals) -> S.Bottom[L, str]

A GraphQL enum: typed as literals but accepting any string, so a value the server adds later still decodes.

ParameterTypeDescription
literalsSequence[L]

Returns S.Bottom[L, str]

def enum_literals[L: str](literals: Sequence[L], /) -> S.Bottom[L, str]:
    """A GraphQL enum: typed as ``literals`` but accepting any string, so
    a value the server adds later still decodes."""

    def any_string(_: str) -> TypeIs[L]:
        return True

    return S.String.pipe(
        S.refine(
            any_string,
            title=f"enum({' | '.join(literals)})",
            description=", ".join(f'"{literal}"' for literal in literals)
            + ", or any string the server adds later",
        )
    )