pify/execute
Effect-based execution. Turns a ShopifyRequest plus a decoder into a
midas Effect that fetches, maps the HTTP status and the GraphQL
envelope, and decodes data.
Shopify reports some failures inside an HTTP 200: THROTTLED and
ACCESS_DENIED arrive as errors[].extensions.code. Any entry in
errors fails the call, even when data is present, because a field
that errored reads as null.
Types
A decoded response and the API version that served it, read from
X-Shopify-API-Version. Shopify serves the oldest accessible version
when the requested one is retired.
pub type Served(a) {
Served(value: a, served_version: option.Option(String))
}
Constructors
-
Served(value: a, served_version: option.Option(String))
Values
pub fn check_status(
response: response.Response(BitArray),
) -> Result(Nil, error.ShopifyError)
Fail on every status outside 2xx with the mapped ShopifyError.
pub fn collect_pages(
fetch_page: fn(option.Option(String)) -> effect.Effect(
Result(graphql.Connection(a), error.ShopifyError),
key,
),
) -> effect.Effect(Result(List(a), error.ShopifyError), key)
Follow pageInfo.endCursor until the last page and keep every node.
pub fn decode_envelope(
body: BitArray,
decoder: decode.Decoder(a),
) -> Result(a, error.ShopifyError)
pub fn handle_response(
response: response.Response(BitArray),
decoder: decode.Decoder(a),
) -> Result(Served(a), error.ShopifyError)
Map the HTTP status, then the GraphQL envelope, then decode data.
pub fn header(
response: response.Response(a),
name: String,
) -> option.Option(String)
pub fn map(
task: effect.Effect(Result(a, error.ShopifyError), key),
transform: fn(a) -> b,
) -> effect.Effect(Result(b, error.ShopifyError), key)
pub fn run(
shopify_request: request.ShopifyRequest,
decoder: decode.Decoder(a),
) -> effect.Effect(Result(a, error.ShopifyError), key)
pub fn run_mutation(
shopify_request: request.ShopifyRequest,
field: String,
decoder: decode.Decoder(a),
) -> effect.Effect(Result(a, error.ShopifyError), key)
Run a mutation whose payload sits at data.<field> next to a
userErrors list. A non-empty list fails with ShopifyErrorUserErrors
before decoder reads the payload.
pub fn run_served(
shopify_request: request.ShopifyRequest,
decoder: decode.Decoder(a),
) -> effect.Effect(Result(Served(a), error.ShopifyError), key)
pub fn send(
shopify_request: request.ShopifyRequest,
handle: fn(response.Response(BitArray)) -> Result(
a,
error.ShopifyError,
),
) -> effect.Effect(Result(a, error.ShopifyError), key)
Fetch and hand the raw response to handle.
pub const served_version_header: String
pub fn then(
task: effect.Effect(Result(a, error.ShopifyError), key),
next: fn(a) -> Result(b, error.ShopifyError),
) -> effect.Effect(Result(b, error.ShopifyError), key)
pub fn try_each(
items: List(a),
run_one: fn(a) -> effect.Effect(
Result(b, error.ShopifyError),
key,
),
) -> effect.Effect(Result(List(b), error.ShopifyError), key)
Run one effect per item, in order, and stop at the first error.