# Call Shopify

Use Shopify’s GraphQL API directly, with credentials held by Littleworks.

Source: https://littleworks.app/docs/shopify

## One GraphQL client

Inside a work, use `await shopify.graphql(query, variables)`. Littleworks manages the store’s connection and credentials. The result is Shopify’s raw GraphQL envelope, including `data`, `errors`, and `extensions` when present.

### Client interface

```javascript
const result = await shopify.graphql(query, variables);

if (result.errors?.length) {
  throw new Error("Shopify could not complete the request");
}

return result.data;
```

The snippet assumes you have defined a query and its variables for your task. Use [Shopify’s Admin GraphQL reference](https://shopify.dev/docs/api/admin-graphql) for operation-specific fields and required access scopes. Mutations may also return operation-specific `userErrors` inside data; inspect those too.

## Declare permission explicitly

Set `permissions.shopify` to `true` in the manifest. This enables the client for the work; it does not grant new Shopify scopes. The store installation’s approved scopes remain the outer limit. Read `get_context` to see those scopes before planning an operation.

### Manifest permission

```json
{
  "permissions": { "shopify": true }
}
```

The current development app requests `read_products` and `read_orders`. Do not assume a work can update products, edit themes, or access all customer data. Some operations also depend on Shopify’s protected-data requirements and order-access limits.

## Preview is not a Shopify sandbox

Preview separates Littleworks documents from Live documents. It uses the same Shopify connection. Read-only checks are useful for testing; mutations, when permitted, affect the real store.

## Handle failures deliberately

A work may have already changed a document or completed a Shopify operation before a later error. Check the run and the affected state before retrying. Littleworks does not promise exactly-once external effects or transactions spanning storage and Shopify.

Keep logs operational. Do not log customer payloads, credentials, or full GraphQL responses containing personal data. See [Inspect and troubleshoot](https://littleworks.app/docs/operations).
