Skip to content
This repository has been archived by the owner on Apr 11, 2024. It is now read-only.

Commit

Permalink
Update documentation to match new format
Browse files Browse the repository at this point in the history
  • Loading branch information
paulomarg committed Dec 19, 2023
1 parent 1533ccf commit 1878109
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 28 deletions.
8 changes: 8 additions & 0 deletions .changeset/nasty-swans-try.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@shopify/storefront-api-client": minor
"@shopify/admin-api-client": minor
"@shopify/graphql-client": minor
"@shopify/shopify-api": minor
---

Updated shopify-api GraphQL clients' APIs to be closer to the underlying clients
34 changes: 17 additions & 17 deletions packages/shopify-api/docs/reference/clients/Graphql.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ The Shopify Session containing an access token to the API.
This will override the default API version.
Any requests made by this client will reach this version instead.

## Query
## Request

Sends a request to the Admin API.

Expand All @@ -54,7 +54,7 @@ Sends a request to the Admin API.
#### Using a query string

```ts
const response = await client.query(
const response = await client.request(
`{
products (first: 10) {
edges {
Expand All @@ -67,13 +67,13 @@ const response = await client.query(
}
}`,
);
console.log(response.headers, response.body);
console.log(response.data, response.extensions);
```

#### Using variables

```ts
const response = await client.query(
const response = await client.request(
`query GetProducts($first: Int!) {
products (first: $first) {
edges {
Expand All @@ -91,7 +91,7 @@ const response = await client.query(
},
},
);
console.log(response.headers, response.body);
console.log(response.data, response.extensions);
```

> **Note**: If using TypeScript, you can pass in a type argument for the response body:
Expand All @@ -104,19 +104,19 @@ interface MyResponseBodyType {
};
}

const response = await client.query<MyResponseBodyType>(/* ... */);
const response = await client.request<MyResponseBodyType>(/* ... */);

// response.body will be of type MyResponseBodyType
console.log(response.body.data);
```

> **Note**: If there are any errors in the response, `query` will throw a `GraphqlQueryError` which includes details from the API response:
> **Note**: If there are any errors in the response, `request` will throw a `GraphqlQueryError` which includes details from the API response:
```ts
import {GraphqlQueryError} from '@shopify/shopify-api';

try {
const products = await client.query(/* ... */);
const products = await client.request(/* ... */);

// No errors, proceed with logic
} catch (error) {
Expand Down Expand Up @@ -144,34 +144,34 @@ The query or mutation string.

The variables for the operation.

#### options.extraHeaders
#### options.headers

`{[key: string]: string | number}`

Add custom headers to the request.

#### options.tries
#### options.retries

`number` | Defaults to `1`, _must be >= 0_
`number` | _Must be between_ `0 and 3`

The maximum number of times to retry the request.

### Return

`Promise<RequestResponse>`
`Promise<ClientResponse>`

Returns an object containing:

#### Headers
#### Data

`{[key: string]: string | string[]}`
`any`

The HTTP headers in the response from Shopify.
The [`data` component](https://shopify.dev/docs/api/admin/getting-started#graphql-admin-api) of the response.

#### Body
#### Extensions

`any`

The HTTP body in the response from Shopify.
The [`extensions` component](https://shopify.dev/docs/api/admin-graphql#rate_limits) of the response.

[Back to shopify.clients](./README.md)
22 changes: 11 additions & 11 deletions packages/shopify-api/docs/reference/clients/Storefront.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ The session for the request.
This will override the default API version.
Any requests made by this client will reach this version instead.

## Query
## Request

Sends a request to the Storefront API.

### Examples

```ts
const products = await storefrontClient.query(
const products = await storefrontClient.request(
`{
products (first: 10) {
edges {
Expand Down Expand Up @@ -93,34 +93,34 @@ The query or mutation string.

The variables for the operation.

#### options.extraHeaders
#### options.headers

`{[key: string]: string | number}`

Add custom headers to the request.

#### options.tries
#### options.retries

`number` | Defaults to `1`, _must be >= 0_
`number` | _Must be between_ `0 and 3`

The maximum number of times to retry the request.

### Return

`Promise<RequestResponse>`
`Promise<ClientResponse>`

Returns an object containing:

#### Headers
#### Data

`{[key: string]: string | string[]}`
`any`

The HTTP headers in the response from Shopify.
The `data` component of the response.

#### Body
#### Extensions

`any`

The HTTP body in the response from Shopify.
The `extensions` component of the response.

[Back to shopify.clients](./README.md)

0 comments on commit 1878109

Please sign in to comment.