Module cowboy_graphql

This module defines the cowboy_graphql behaviour.
Required callback functions: connection/2, init/3, handle_request/6, handle_cancel/2, handle_info/2, terminate/2.

Data Types

auth_error()

auth_error() = {auth_error, Msg::unicode:chardata() | atom(), Extra::json_object()}

Authentication errors. Should only happen in connect and init callbacks.

error()

error() = request_validation_error() | auth_error() | protocol_error() | other_error()

Only types of error which are allowed to be returned from callbacks.

error_location()

error_location() = #{line => pos_integer(), column => pos_integer()}

graphql_error()

graphql_error() = #{message := unicode:unicode_binary(), locations => [error_location()], path => [unicode:unicode_binary() | non_neg_integer()], extensions => json_object()}

json()

json() = json_object() | json_array() | json_scalar()

json_array()

json_array() = [json()]

json_object()

json_object() = #{json_string() => json()}

json_scalar()

json_scalar() = json_string() | integer() | float() | boolean() | null

json_string()

json_string() = unicode:unicode_binary()

other_error()

other_error() = {other_error, Msg::unicode:chardata(), Extra::json_object()}

Errors not matching any other category.

protocol_error()

protocol_error() = {protocol_error, Transport::http | ws, Code::atom(), Msg::unicode:chardata(), Extra::json_object()}

Errors in transport protocols (malformed HTTP / WS requests and packets). Normally generated internally by protocol handlers, but may be produced by connect callback as result of validation of Req parameter.

request_id()

request_id() = binary()

request_validation_error()

request_validation_error() = {request_error, request_id(), graphql_error()}

Errors in GraphQL execution which happened before the actual execution have started, eg. during syntax / semantics / datatype validation. Errors generated during GraphQL "field resolve" phase are returned as {ok, #{errors => [..]}}

result()

result() = {Id::request_id(), Done::boolean(), Data::json_object() | undefined, Errors::[graphql_error()], Extensions::json_object()}

Function Index

auth_error/2
graphql_error/3Creates an execution_error() structure.
http_config/3Generate HTTP handler's cowboy_router "InitialState".
other_error/2
protocol_error/4
request_validation_error/2
ws_config/3Generate WebSocket handler's cowboy_router "InitialState".

Function Details

auth_error/2

auth_error(Msg::unicode:chardata(), Extra::map()) -> auth_error()

graphql_error/3

graphql_error(Message::unicode:chardata(), Locations::[error_location()], Extensions::map()) -> graphql_error()

Creates an execution_error() structure

http_config/3

http_config(Callback::module(), CallbackOpts::any(), TransportOpts::cowboy_graphql_http_handler:options()) -> cowboy_graphql_http_handler:config()

Generate HTTP handler's cowboy_router "InitialState".

Usage:
  Routes = [
    ...,
    {"/api/graphql/http",
     cowboy_graphql_http_handler,
     cowboy_graphql:http_config(my_graphql_handler, MyOpts, #{max_body_size => 5 * 1024 * 1024})},
    ...
  ]
See [https://ninenines.eu/docs/en/cowboy/2.9/manual/cowboy_router/]

other_error/2

other_error(Msg::unicode:chardata(), Extra::map()) -> other_error()

protocol_error/4

protocol_error(Transport::ws | http, Code::atom(), Msg::unicode:chardata(), Extra::map()) -> protocol_error()

request_validation_error/2

request_validation_error(Id::request_id(), Extra::graphql_error()) -> request_validation_error()

ws_config/3

ws_config(Callback::module(), CallbackOpts::any(), TransportOpts::cowboy_graphql_ws_handler:options()) -> cowboy_graphql_ws_handler:config()

Generate WebSocket handler's cowboy_router "InitialState".

Usage:
  Routes = [
    ...,
    {"/api/graphql/websocket",
     cowboy_graphql_ws_handler,
     cowboy_graphql:ws_config(my_graphql_handler, MyOpts, #{max_body_size => 5 * 1024 * 1024})},
    ...
  ]
See [https://ninenines.eu/docs/en/cowboy/2.9/manual/cowboy_router/]


Generated by EDoc