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#
| Attribute | Type | Description |
|---|---|---|
url | Callable[[Kind, str], Effect[str]] | None |
|
Functions#
__init__#
__init__(*, execute, subscribe, url=None) -> None| Parameter | Type | Description |
|---|---|---|
execute | Callable[[GraphQLRequest], Effect[Answer, TransportError]] | |
subscribe | Callable[[GraphQLRequest], Stream[Answer, TransportError]] | |
url | Callable[[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 = urlexecute#
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.
| Parameter | Type | Description |
|---|---|---|
request | GraphQLRequest |
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.
| Parameter | Type | Description |
|---|---|---|
request | GraphQLRequest |
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)