ExShopifyApp.Graphql (ex_shopify_app v1.2.0)
A minimal Shopify Admin GraphQL client, plus GID helpers.
The client is authenticated with a shop's shopify_domain and offline
access_token (an ExShopifyApp.Shop.authorized/0 reference). The
ExShopifyApp.AccessToken.Token struct already carries both fields, so it can be
passed directly; any map/struct exposing :shopify_domain and :access_token
works too.
Summary
Functions
Returns the base URI for the Shopify Admin API.
Returns an authenticated Tesla client for the Shopify Admin GraphQL API.
Ensures the given id is a valid Shopify GID for resource.
Sends a GraphQL request to the Shopify Admin API.
Converts a Shopify GID to its trailing integer id.
Unwraps a query/3 result, surfacing transport, HTTP, and GraphQL errors.
Functions
Returns the base URI for the Shopify Admin API.
@spec client( ExShopifyApp.Shop.authorized(), keyword() ) :: Tesla.Client.t()
Returns an authenticated Tesla client for the Shopify Admin GraphQL API.
Options
:api_version- the Shopify API version, defaults toExShopifyApp.api_version/0.:debug- whentrue, logs requests/responses. Defaults tofalse.
Ensures the given id is a valid Shopify GID for resource.
Already-formed GIDs are returned unchanged.
Examples
iex> ExShopifyApp.Graphql.ensure_gid(1, "shop")
"gid://shopify/Shop/1"
iex> ExShopifyApp.Graphql.ensure_gid("gid://shopify/Shop/1", "shop")
"gid://shopify/Shop/1"
@spec query(Tesla.Client.t(), String.t(), map()) :: Tesla.Env.result()
Sends a GraphQL request to the Shopify Admin API.
@spec trim_gid(String.t()) :: pos_integer()
Converts a Shopify GID to its trailing integer id.
Examples
iex> ExShopifyApp.Graphql.trim_gid("gid://shopify/Shop/1")
1
@spec unwrap(Tesla.Env.result(), (map() | nil -> result)) :: result when result: {:ok, term()} | {:error, term()}
Unwraps a query/3 result, surfacing transport, HTTP, and GraphQL errors.
On a 200 response, a non-empty top-level "errors" array yields
{:error, {:graphql, errors}}; otherwise the response's "data" map is passed to
fun, which returns the final {:ok, term} | {:error, term}. Non-200 responses
collapse to {:error, %Tesla.Env{}} and transport errors to {:error, reason}.