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

Commit cdabf56

Browse files
authored
Update Admin Client README.md (#1153)
* Update README.md * Empty changeset
1 parent 7d4e72d commit cdabf56

File tree

2 files changed

+47
-40
lines changed

2 files changed

+47
-40
lines changed

.changeset/polite-bugs-sneeze.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
---

packages/admin-api-client/README.md

Lines changed: 45 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
# Admin API Client
22

3-
The Admin API Client library is for developers who want to interact with Shopify's GraphQL `Admin API`. The features of this library are designed to be lightweight and minimally opinionated.
4-
5-
## Getting Started
6-
7-
Install the package:
3+
The Admin API Client library is for developers who want to interact with Shopify's `Admin API`. The features of this library are designed to be lightweight and minimally opinionated.
84

95
```
106
npm install @shopify/admin-api-client -s
117
```
128

9+
- [GraphQL Client](#graphql-client)
10+
- [REST Client](#rest-client)
11+
12+
## GraphQL Client
13+
14+
### Getting Started
15+
1316
Initialize the client:
1417

1518
```typescript
@@ -45,7 +48,7 @@ const {data, errors, extensions} = await client.request(operation, {
4548
> [!NOTE]
4649
> If you want to query the Admin REST API, you can [use the REST client](#using-the-rest-api-client) instead.
4750
48-
### `createAdminApiClient()` parameters
51+
#### `createAdminApiClient()` parameters
4952

5053
| Property | Type | Description |
5154
| ------------------- | ---------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
@@ -57,7 +60,7 @@ const {data, errors, extensions} = await client.request(operation, {
5760
| customFetchApi? | `(url: string, init?: {method?: string, headers?: HeaderInit, body?: string}) => Promise<Response>` | A replacement `fetch` function that will be used in all client network requests. By default, the client uses `window.fetch()`. |
5861
| logger? | `(logContent:`[`UnsupportedApiVersionLog`](#unsupportedapiversionlog) ` \| `[`HTTPResponseLog`](#httpresponselog)`\|`[`HTTPRetryLog`](#httpretrylog)`) => void` | A logger function that accepts [log content objects](#log-content-types). This logger will be called in certain conditions with contextual information. |
5962

60-
## Client properties
63+
### Client properties
6164

6265
| Property | Type | Description |
6366
| ------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
@@ -67,7 +70,7 @@ const {data, errors, extensions} = await client.request(operation, {
6770
| fetch | `(operation: string, options?:`[`AdminAPIClientRequestOptions`](#adminapiclientrequestoptions-properties)`) => Promise<Response>` | Fetches data from Admin API using the provided GQL `operation` string and [`AdminAPIClientRequestOptions`](#adminapiclientrequestoptions-properties) object and returns the network response. |
6871
| request | `<TData>(operation: string, options?:`[`AdminAPIClientRequestOptions`](#adminapiclientrequestoptions-properties)`) => Promise<`[`ClientResponse<TData>`](#clientresponsetdata)`>` | Requests data from Admin API using the provided GQL `operation` string and [`AdminAPIClientRequestOptions`](#adminapiclientrequestoptions-properties) object and returns a normalized response object. |
6972

70-
## `AdminApiClientConfig` properties
73+
### `AdminApiClientConfig` properties
7174

7275
| Name | Type | Description |
7376
| -------------- | ------------------------ | ---------------------------------------------------- |
@@ -78,7 +81,7 @@ const {data, errors, extensions} = await client.request(operation, {
7881
| apiUrl | `string` | The API URL generated from the provided store domain and api version |
7982
| retries? | `number` | The number of retries the client will attempt when the API responds with a `Too Many Requests (429)` or `Service Unavailable (503)` response |
8083

81-
## `ApiClientRequestOptions` properties
84+
### `ApiClientRequestOptions` properties
8285

8386
| Name | Type | Description |
8487
| -------------- | ------------------------ | ---------------------------------------------------- |
@@ -87,15 +90,15 @@ const {data, errors, extensions} = await client.request(operation, {
8790
| headers? | `{[key: string]: string}`| Customized headers to be included in the API request |
8891
| retries? | `number` | Alternative number of retries for the request. Retries only occur for requests that were abandoned or if the server responds with a `Too Many Request (429)` or `Service Unavailable (503)` response. Minimum value is `0` and maximum value is `3`. |
8992

90-
## `ClientResponse<TData>`
93+
### `ClientResponse<TData>`
9194

9295
| Name | Type | Description |
9396
| ----------- | ------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
9497
| data? | `TData \| any` | Data returned from the Admin API. If `TData` was provided to the function, the return type is `TData`, else it returns type `any`. |
9598
| errors? | [`ResponseErrors`](#responseerrors) | Error object that contains any API or network errors that occured while fetching the data from the API. It does not include any `UserErrors`. |
9699
| extensions? | `{[key: string]: any}` | Additional information on the GraphQL response data and context. It can include the `context` object that contains the localization context information used to generate the returned API response. |
97100

98-
## `ResponseErrors`
101+
### `ResponseErrors`
99102

100103
| Name | Type | Description |
101104
| ----------- | --------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
@@ -104,12 +107,12 @@ const {data, errors, extensions} = await client.request(operation, {
104107
| graphQLErrors? | `any[]` | The GraphQL API errors returned by the server |
105108
| response? | `Response` | The raw response object from the network fetch call |
106109

107-
### Client `request()` response examples
110+
#### Client `request()` response examples
108111

109112
<details>
110113
<summary>Successful response</summary>
111114

112-
### API response
115+
#### API response
113116

114117
```json
115118
{
@@ -139,7 +142,7 @@ const {data, errors, extensions} = await client.request(operation, {
139142
<details>
140143
<summary>Error responses</summary>
141144

142-
### Network error
145+
#### Network error
143146

144147
```json
145148
{
@@ -148,7 +151,7 @@ const {data, errors, extensions} = await client.request(operation, {
148151
}
149152
```
150153

151-
### Admin API graphQL error
154+
#### Admin API graphQL error
152155

153156
```json
154157
{
@@ -176,9 +179,9 @@ const {data, errors, extensions} = await client.request(operation, {
176179

177180
</details>
178181

179-
## Usage examples
182+
### Usage examples
180183

181-
### Query for a product
184+
#### Query for a product
182185

183186
```typescript
184187
const productQuery = `
@@ -198,7 +201,7 @@ const {data, errors, extensions} = await client.request(productQuery, {
198201
});
199202
```
200203

201-
### Dynamically set the Admin API version per data fetch
204+
#### Dynamically set the Admin API version per data fetch
202205

203206
```typescript
204207
const productQuery = `
@@ -219,7 +222,7 @@ const {data, errors, extensions} = await client.request(productQuery, {
219222
});
220223
```
221224

222-
### Add custom headers to API request
225+
#### Add custom headers to API request
223226

224227
```typescript
225228
const productQuery = `
@@ -242,7 +245,7 @@ const {data, errors, extensions} = await client.request(productQuery, {
242245
});
243246
```
244247

245-
### Using `client.fetch()` to get API data
248+
#### Using `client.fetch()` to get API data
246249

247250
```typescript
248251
const shopQuery = `
@@ -260,7 +263,7 @@ if (response.ok) {
260263
}
261264
```
262265

263-
### Dynamically set the number of retries per request
266+
#### Dynamically set the number of retries per request
264267

265268
```typescript
266269
const productQuery = `
@@ -281,7 +284,7 @@ const {data, errors, extensions} = await client.request(productQuery, {
281284
});
282285
```
283286

284-
## Typing variables and return objects
287+
### Typing variables and return objects
285288

286289
This client is compatible with the `@shopify/api-codegen-preset` package.
287290
You can use that package to create types from your operations with the [Codegen CLI](https://www.graphql-cli.com/codegen/).
@@ -329,9 +332,9 @@ There are different ways to [configure codegen](https://github.com/Shopify/shopi
329332
Once the script runs, it'll create the file `./types/admin.generated.d.ts`.
330333
When TS includes that file, it'll automatically cause the client to detect the types for each query.
331334
332-
## Log Content Types
335+
### Log Content Types
333336
334-
### `UnsupportedApiVersionLog`
337+
#### `UnsupportedApiVersionLog`
335338
336339
This log content is sent to the logger whenever an unsupported API version is provided to the client.
337340
@@ -340,7 +343,7 @@ This log content is sent to the logger whenever an unsupported API version is pr
340343
| type | `LogType['Unsupported_Api_Version']` | The type of log content. Is always set to `Unsupported_Api_Version` |
341344
| content | `{apiVersion: string, supportedApiVersions: string[]}` | Contextual info including the provided API version and the list of currently supported API versions. |
342345
343-
### `HTTPResponseLog`
346+
#### `HTTPResponseLog`
344347
345348
This log content is sent to the logger whenever a HTTP response is received by the client.
346349
@@ -349,7 +352,7 @@ This log content is sent to the logger whenever a HTTP response is received by t
349352
| type | `LogType['HTTP-Response']` | The type of log content. Is always set to `HTTP-Response` |
350353
| content | `{`[`requestParams`](#requestparams)`: [url, init?], response: Response}` | Contextual data regarding the request and received response |
351354
352-
### `HTTPRetryLog`
355+
#### `HTTPRetryLog`
353356
354357
This log content is sent to the logger whenever the client attempts to retry HTTP requests.
355358
@@ -358,14 +361,16 @@ This log content is sent to the logger whenever the client attempts to retry HTT
358361
| type | `LogType['HTTP-Retry']` | The type of log content. Is always set to `HTTP-Retry` |
359362
| content | `{`[`requestParams`](#requestparams)`: [url, init?], lastResponse?: Response, retryAttempt: number, maxRetries: number}` | Contextual data regarding the upcoming retry attempt. <br /><br/>`requestParams`: [parameters](#requestparams) used in the request<br/>`lastResponse`: previous response <br/> `retryAttempt`: the current retry attempt count <br/> `maxRetries`: the maximum number of retries |
360363
361-
### `RequestParams`
364+
#### `RequestParams`
362365
363366
| Property | Type | Description |
364367
| -------- | ------------------------ | ---------------------------------- |
365368
| url | `string` | Requested URL |
366369
| init? | `{method?: string, headers?: HeaderInit, body?: string}` | The request information |
367370
368-
## Using the REST API client
371+
## REST Client
372+
373+
### Getting Started
369374
370375
Initialize the client:
371376
@@ -389,7 +394,7 @@ if (response.ok) {
389394
}
390395
```
391396
392-
### `createAdminRestApiClient()` parameters
397+
#### `createAdminRestApiClient()` parameters
393398
394399
| Property | Type | Description |
395400
| ------------------- | ----------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
@@ -404,7 +409,7 @@ if (response.ok) {
404409
| defaultRetryTime? | `number` | How long to wait for a retry when missing the `Retry-After` header |
405410
| formatPaths? | `boolean` | Whether to format paths, e.g. `products/123` => `/products/123.json` |
406411
407-
## Client properties
412+
### Client properties
408413
409414
| Property | Type | Description |
410415
| ------------- | --------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
@@ -413,7 +418,7 @@ if (response.ok) {
413418
| put | `(path: string, options?:`[`PutRequestOptions`](#putrequestoptions-properties)`) => Promise<Response>` | Performs a PUT request to the API. |
414419
| delete | `(path: string, options?:`[`DeleteRequestOptions`](#deleterequestoptions-properties)`) => Promise<Response>` | Performs a DELETE request to the API. |
415420
416-
## `GetRequestOptions` properties
421+
### `GetRequestOptions` properties
417422
418423
| Name | Type | Description |
419424
| ------------- | --------------------------------------- | ----------------------------------------------------- |
@@ -423,21 +428,21 @@ if (response.ok) {
423428
| retries? | `number` | Alternative number of retries for the request. Retries only occur for requests that were abandoned or if the server responds with a `Too Many Request (429)` or `Service Unavailable (503)` response. Minimum value is `0` and maximum value is `3.` |
424429
| data? | `{ [key: string]: any } \| string` | Request body data. |
425430
426-
## `PostRequestOptions` properties
431+
### `PostRequestOptions` properties
427432
428433
Same options as for [GET requests](#getrequestoptions-properties), but `data` isn't optional.
429434
430-
## `PutRequestOptions` properties
435+
### `PutRequestOptions` properties
431436
432437
Same options as for [POST requests](#postrequestoptions-properties).
433438
434-
## `DeleteRequestOptions` properties
439+
### `DeleteRequestOptions` properties
435440
436441
Same options as for [GET requests](#getrequestoptions-properties).
437442
438-
## Usage examples
443+
### Usage examples
439444
440-
### Query for a product
445+
#### Query for a product
441446
442447
```typescript
443448
const response = await client.get("products/1234567890");
@@ -447,7 +452,7 @@ if (response.ok) {
447452
}
448453
```
449454
450-
### Update a product
455+
#### Update a product
451456
452457
```typescript
453458
const response = await client.put("products/1234567890",
@@ -465,7 +470,7 @@ if (response.ok) {
465470
}
466471
```
467472
468-
### Dynamically set the Admin API version per data fetch
473+
#### Dynamically set the Admin API version per data fetch
469474
470475
```typescript
471476
const response = await client.get("products/1234567890",
@@ -479,7 +484,7 @@ if (response.ok) {
479484
}
480485
```
481486
482-
### Add custom headers to API request
487+
#### Add custom headers to API request
483488
484489
```typescript
485490
const response = await client.get("products/1234567890",
@@ -495,7 +500,7 @@ if (response.ok) {
495500
}
496501
```
497502
498-
### Dynamically set the number of retries per request
503+
#### Dynamically set the number of retries per request
499504
500505
```typescript
501506
const response = await client.get("products/1234567890",

0 commit comments

Comments
 (0)