GitHub

GraphQLProtocolService

API reference for GraphQLProtocolService.

A transport: execute sends a query or mutation, subscribe a subscription. url resolves the endpoint of an operation, when the transport has one. GraphQLProtocolService(execute=..., subscribe=...) makes one of functions (a test double, say).

Attributes

AttributeTypeDescription
urlCallable[[Kind, str], Effect[str]] | None

url(kind, operation_name) resolves the endpoint the transport sends that operation to (resolver batches group by it), or None when the transport has no per-operation URL (the WebSocket transport).

Functions

__init__

__init__(*, execute, subscribe, url=None) -> None
ParameterTypeDescription
executeCallable[[GraphQLRequest], Effect[Answer, TransportError]]
subscribeCallable[[GraphQLRequest], Stream[Answer, TransportError]]
urlCallable[[Kind, str], Effect[str]] | None = None
def __init__(
    self,
    *,
    execute: Callable[[GraphQLRequest], Effect[Answer, TransportError]],
    subscribe: Callable[[GraphQLRequest], Stream[Answer, TransportError]],
    url: Callable[[Kind, str], Effect[str]] | None = None,
) -> None:
    self._execute = execute
    self._subscribe = subscribe
    self._url = url

execute

execute(request) -> Effect[Answer, TransportError]

Sends the query or mutation request and succeeds with the Answer the server gave, whatever its HTTP status. Fails with a TransportError when the request could not be sent or the answer is not a GraphQL response.

ParameterTypeDescription
requestGraphQLRequest

Returns Effect[Answer, TransportError]

def execute(self, request: GraphQLRequest) -> Effect[Answer, TransportError]:
    """Sends the query or mutation ``request`` and succeeds with the
    ``Answer`` the server gave, whatever its HTTP status. Fails with a
    ``TransportError`` when the request could not be sent or the answer
    is not a GraphQL response."""
    return self._execute(request)

subscribe

subscribe(request) -> Stream[Answer, TransportError]

Runs the subscription request: a stream of every Answer the server sends, ending when the server completes it. Fails with a TransportError when the subscription could not be opened or the connection breaks.

ParameterTypeDescription
requestGraphQLRequest

Returns Stream[Answer, TransportError]

def subscribe(self, request: GraphQLRequest) -> Stream[Answer, TransportError]:
    """Runs the subscription ``request``: a stream of every ``Answer``
    the server sends, ending when the server completes it. Fails with a
    ``TransportError`` when the subscription could not be opened or the
    connection breaks."""
    return self._subscribe(request)