# GraphQL

Source: https://developers.swell.is/frontend-api/frontend-libraries/graphql

Swell's GraphQL server allows you to implement frontend features like displaying products, managing carts, and applying discounts.

> **Warning:** The GraphQL API is in an experimental alpha state and has multiple limitations detailed below. We intend to release a new version in the future with an improved implementation, but do not have a development timeframe. The current API will remain available, however features and bug fixes will not be prioritized.

### Features

- Pre-load storefront pages by fetching specific products, categories, store settings, nav menus, and custom content ahead of time
- Create, recover, and update accounts
- Manage changes and statuses of shopping carts
- Authenticate customers and allow them to edit account details, orders, and subscriptions
- Format prices in localized currencies

### Limitations

- Does not support nested queries
- Does not return records from the `content` model namespace in results unless they have `published: true`
- Does not support custom input arguments for client-side field editing
- Does not return saved customer cards and addresses
- Cannot render payment elements or tokenize cards, as this requires insertion of secure DOM elements
- Cannot update cart email for guest checkout flows
- Cannot recover abandoned carts

### Playground

Swell offers a GraphQL playground to test and optimize your queries. To use it, login to your dashboard and navigate directly to `https://<your-store-id>.swell.store/playground`.

Start by adding your public key to the HTTP Headers section.

**Authorization header**

**GraphQL**

```json
{
  "Authorization": "pk_test..."
}
```

### Server endpoint

Your store's GraphQL server is available at `https://<your-store-id>.swell.store/graphql/v2`. You will need to include the authorization header as shown above.

### Query parameters

Queries accept the following arguments. Combine them as needed: for example, `(limit: 5, page: 1)` returns the first page of results, 5 per page.

| Argument | Type | Description |
| --- | --- | --- |
| id | String | ID of the record to return, in single-record queries. |
| slug | String | Slug of the record to return, in single-record queries on models that have one, such as products and categories. |
| number | String | Number of the record to return, in single-record queries on models identified by number, such as orders. |
| search | String | Text to search results by. |
| where | JSON | Criteria to filter results by field values. |
| sort | String | Field to sort results by, for example `name`. |
| limit | Int | Maximum number of results to return. |
| page | Int | Page of results to return. |
| _locale | String | Locale code to return content in, with or without a country code, for example `en` or `en-US`. |
| _currency | String | Three-letter ISO currency code to return prices in, for example `USD`. |
| _pricing | ProductPricing | Product queries only. An object with `quantity` and `accountId` to calculate prices for. |
| _preview | Boolean | Content model queries only. Indicates whether to return preview content. |
