GraphQL transports (Effect's GraphQLProtocol).
The client sends every operation through the GraphQLProtocol service:
execute for queries and mutations, subscribe for subscriptions.
layer_http / make_http speak GraphQL over HTTP, with subscriptions
over graphql-sse, or over graphql-transport-ws with web_socket=;
layer_web_socket / make_web_socket run every operation over
graphql-transport-ws. A test may provide any GraphQLProtocolService.
Re-exports#
Types#
| Type | Definition | Description |
|---|---|---|
QueryMethod | type QueryMethod = Literal['GET', 'POST'] | |
Url | type Url = str | Effect[str] | Callable[[UrlOptions], str] | An endpoint: fixed, resolved by an effect in each call's context, or chosen per call from the caller's services and the operation. |
Kind | type Kind = Literal['query', 'mutation', 'subscription'] |
Classes#
Functions#
make_http#
make_http(*, url: Url, query_method: QueryMethod = 'POST', web_socket: None = None) -> Effect[GraphQLProtocolService, Never, HttpClient]
make_http[R](*, url: str, query_method: QueryMethod = 'POST', web_socket: WebSocketOptions[R]) -> Effect[GraphQLProtocolService, Never, HttpClient | WebSocketConstructor | Scope | R]A transport POSTing queries and mutations as JSON to url
(queries as GET URL params with query_method="GET") and running
subscriptions over graphql-sse, or over graphql-transport-ws with
web_socket (whose connection lives in the current scope).
| Parameter | Type | Description |
|---|---|---|
url | ||
query_method | = 'POST' | |
web_socket | = None |
@overload
def make_http(
*, url: Url, query_method: QueryMethod = "POST", web_socket: None = None
) -> Effect[GraphQLProtocolService, Never, HttpClient]: ...
@overload
def make_http[R](
*, url: str, query_method: QueryMethod = "POST", web_socket: WebSocketOptions[R]
) -> Effect[GraphQLProtocolService, Never, HttpClient | WebSocketConstructor | Scope | R]: ...
def make_http(
*,
url: Url,
query_method: QueryMethod = "POST",
web_socket: WebSocketOptions[Any] | None = None,
) -> Effect[GraphQLProtocolService, Never, Any]:
"""A transport POSTing queries and mutations as JSON to ``url``
(queries as GET URL params with ``query_method="GET"``) and running
subscriptions over graphql-sse, or over graphql-transport-ws with
``web_socket`` (whose connection lives in the current scope)."""
return _make_http(url, query_method, web_socket)layer_http#
layer_http(*, url: Url, query_method: QueryMethod = 'POST', web_socket: None = None) -> Layer[GraphQLProtocol, Never, HttpClient]
layer_http[R](*, url: str, query_method: QueryMethod = 'POST', web_socket: WebSocketOptions[R]) -> Layer[GraphQLProtocol, Never, HttpClient | WebSocketConstructor | R]make_http as a layer.
| Parameter | Type | Description |
|---|---|---|
url | ||
query_method | = 'POST' | |
web_socket | = None |
@overload
def layer_http(
*, url: Url, query_method: QueryMethod = "POST", web_socket: None = None
) -> Layer[GraphQLProtocol, Never, HttpClient]: ...
@overload
def layer_http[R](
*, url: str, query_method: QueryMethod = "POST", web_socket: WebSocketOptions[R]
) -> Layer[GraphQLProtocol, Never, HttpClient | WebSocketConstructor | R]: ...
def layer_http(
*,
url: Url,
query_method: QueryMethod = "POST",
web_socket: WebSocketOptions[Any] | None = None,
) -> Layer[GraphQLProtocol, Never, Any]:
"""``make_http`` as a layer."""
return layer_effect(GraphQLProtocol, _make_http(url, query_method, web_socket))make_web_socket#
make_web_socket[R = Never](options) -> Effect[GraphQLProtocolService, Never, WebSocketConstructor | Scope | R]A transport running every operation over one shared
graphql-transport-ws connection, opened on the first operation and
living in the current scope (see WebSocketOptions). Per-call
headers and URL params are not sent: graphql-ws has none per
operation.
| Parameter | Type | Description |
|---|---|---|
options | WebSocketOptions[R] |
Returns Effect[GraphQLProtocolService, Never, WebSocketConstructor | Scope | R]
def make_web_socket[R = Never](
options: WebSocketOptions[R],
) -> Effect[GraphQLProtocolService, Never, WebSocketConstructor | Scope | R]:
"""A transport running every operation over one shared
graphql-transport-ws connection, opened on the first operation and
living in the current scope (see ``WebSocketOptions``). Per-call
headers and URL params are not sent: graphql-ws has none per
operation."""
return make_web_socket_protocol(options)layer_web_socket#
layer_web_socket[R = Never](options) -> Layer[GraphQLProtocol, Never, WebSocketConstructor | R]make_web_socket as a layer.
| Parameter | Type | Description |
|---|---|---|
options | WebSocketOptions[R] |
Returns Layer[GraphQLProtocol, Never, WebSocketConstructor | R]
def layer_web_socket[R = Never](
options: WebSocketOptions[R],
) -> Layer[GraphQLProtocol, Never, WebSocketConstructor | R]:
"""``make_web_socket`` as a layer."""
return layer_effect(GraphQLProtocol, make_web_socket(options))