The functions in this module let you perform HTTP requests to conventional GraphQL server endpoints.
An error returned by the GraphQL server that indicates there was something wrong with the request.
A location in a GraphQL request document.
Takes a URL and a Query Request and returns a Task that you can perform with Task.attempt which will send a POST request to a GraphQL server at the given endpoint.
Takes a URL and a Mutation Request and returns a Task that you can perform with Task.attempt which will send a POST request to a GraphQL server at the given endpoint.
Options available for customizing GraphQL HTTP requests. method should be either "GET" or "POST". For GET requests, the url is modified to include extra parameters in the query string for the GraphQL document and variables. Otherwise, the document and variables are included in the HTTP request body.
Like sendQuery, but takes an RequestOptions value instead of a URL to let you further customize the HTTP request.
Like sendMutation, but takes an RequestOptions value instead of a URL to let you further customize the HTTP request.
Like sendQuery, but takes an RequestOptions value instead of a URL to let you further customize the HTTP request. You will get a plain Http.Response as Task result.
Useful for things like caching, custom errors decoding, etc.
Example of response decoding:
let
decoder =
GraphQL.Request.Builder.responseDataDecoder request
|> Json.Decode.field "data"
options =
{ method = "GET"
, headers = []
, url = "/graphql"
, timeout = Nothing
, withCredentials = False
}
in
request
|> GraphQL.Client.Http.customSendQueryRaw options
|> Task.andThen
(\response ->
case Json.Decode.decodeString decoder response.body of
Err err ->
Task.fail <| GraphQL.Client.Http.HttpError <| Http.BadPayload err response
Ok decodedValue ->
Task.succeed decodedValue
)Like sendMutation, but takes an RequestOptions value instead of a URL to let you further customize the HTTP request. You will get a plain Http.Response as Task result.
Useful for things like custom errors decoding, etc.
Example of response decoding:
let
decoder =
GraphQL.Request.Builder.responseDataDecoder mutationRequest
|> Json.Decode.field "data"
options =
{ method = "GET"
, headers = []
, url = "/graphql"
, timeout = Nothing
, withCredentials = False
}
in
mutationRequest
|> GraphQL.Client.Http.customSendMutationRaw options
|> Task.andThen
(\response ->
case Json.Decode.decodeString decoder response.body of
Err err ->
Task.fail <| GraphQL.Client.Http.HttpError <| Http.BadPayload err response
Ok decodedValue ->
Task.succeed decodedValue
)
Represents errors that can occur when sending a GraphQL request over HTTP.