squall
Types
A GraphQL client with endpoint and headers configuration. This client follows the sans-io pattern: it builds HTTP requests but doesn’t send them. You must use your own HTTP client to send the requests.
pub type Client {
Client(endpoint: String, headers: List(#(String, String)))
}
Constructors
-
Client(endpoint: String, headers: List(#(String, String)))
Values
pub fn new(
endpoint: String,
headers: List(#(String, String)),
) -> Client
Create a new GraphQL client with custom headers.
Example
let client = squall.new("https://api.example.com/graphql", [])
pub fn new_with_auth(endpoint: String, token: String) -> Client
Create a new GraphQL client with bearer token authentication.
Example
let client = squall.new_with_auth("https://api.example.com/graphql", "my-token")
pub fn parse_response(
body: String,
decoder: decode.Decoder(a),
) -> Result(a, String)
Parse a GraphQL response body using the provided decoder. This function decodes the JSON response and extracts the data field.
Example
let decoder = decode.field("users", decode.list(user_decoder))
case squall.parse_response(response_body, decoder) {
Ok(users) -> io.println("Got users!")
Error(err) -> io.println("Parse error: " <> err)
}
pub fn prepare_request(
client: Client,
query: String,
variables: json.Json,
) -> Result(request.Request(String), String)
Prepare an HTTP request for a GraphQL query. This function builds the request but does not send it. You must send the request using your own HTTP client.
Example
let client = squall.new("https://api.example.com/graphql", [])
let request = squall.prepare_request(
client,
"query { users { id name } }",
json.object([]),
)
// Send with your HTTP client (Erlang example)
let assert Ok(response) = httpc.send(request)
// Parse the response
let assert Ok(data) = squall.parse_response(response.body, your_decoder)