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

Commit

Permalink
Merge pull request #1084 from Shopify/ml-graphql-client-error-response
Browse files Browse the repository at this point in the history
[GraphQL Client] Add raw response object to ResponseError
  • Loading branch information
melissaluu authored Dec 4, 2023
2 parents d75efce + 2b9e06f commit 1c4f8de
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .changeset/purple-bears-end.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@shopify/storefront-api-client": minor
"@shopify/admin-api-client": minor
"@shopify/graphql-client": minor
---

Add the raw network response object to `ResponseErrors`
1 change: 1 addition & 0 deletions packages/admin-api-client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ const {data, errors, extensions} = await client.request(operation, {
| networkStatusCode? | `number` | HTTP response status code |
| message? | `string` | The provided error message |
| graphQLErrors? | `any[]` | The GraphQL API errors returned by the server |
| response? | `Response` | The raw response object from the network fetch call |

### Client `request()` response examples

Expand Down
1 change: 1 addition & 0 deletions packages/graphql-client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ const client = createGraphQLClient({
| networkStatusCode? | `number` | HTTP response status code |
| message? | `string` | The provided error message |
| graphQLErrors? | `any[]` | The GraphQL API errors returned by the server |
| response? | `Response` | The raw response object from the network fetch call |


## Usage examples
Expand Down
3 changes: 3 additions & 0 deletions packages/graphql-client/src/graphql-client/graphql-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ async function processJSONResponse<TData = any>(
? GQL_API_ERROR
: `${CLIENT}: An unknown error has occurred. The API did not return a data object or any errors in its response.`,
...(errors ? { graphQLErrors: errors } : {}),
response,
},
}
: {}),
Expand Down Expand Up @@ -191,6 +192,7 @@ function generateRequest(
errors: {
networkStatusCode: status,
message: statusText,
response,
},
};
}
Expand All @@ -200,6 +202,7 @@ function generateRequest(
errors: {
networkStatusCode: status,
message: `${UNEXPECTED_CONTENT_TYPE_ERROR} ${contentType}`,
response,
},
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,7 @@ describe("GraphQL Client", () => {
expect(response).toHaveProperty("errors", {
networkStatusCode: responseConfig.status,
message: responseConfig.statusText,
response: mockedSuccessResponse,
});
});

Expand Down Expand Up @@ -840,6 +841,7 @@ describe("GraphQL Client", () => {
expect(response).toHaveProperty("errors", {
networkStatusCode: responseConfig.status,
message: `GraphQL Client: Response returned unexpected Content-Type: ${contentType}`,
response: mockedSuccessResponse,
});
});

Expand All @@ -865,6 +867,7 @@ describe("GraphQL Client", () => {
message:
"GraphQL Client: An error occurred while fetching from the API. Review 'graphQLErrors' for details.",
graphQLErrors: gqlError,
response: mockedSuccessResponse,
});
});

Expand All @@ -887,6 +890,7 @@ describe("GraphQL Client", () => {
networkStatusCode: mockedSuccessResponse.status,
message:
"GraphQL Client: An unknown error has occurred. The API did not return a data object or any errors in its response.",
response: mockedSuccessResponse,
});
});

Expand Down Expand Up @@ -915,6 +919,7 @@ describe("GraphQL Client", () => {
message:
"GraphQL Client: An error occurred while fetching from the API. Review 'graphQLErrors' for details.",
graphQLErrors: gqlError,
response: mockedSuccessResponse,
});
});
});
Expand Down
1 change: 1 addition & 0 deletions packages/graphql-client/src/graphql-client/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface ResponseErrors {
networkStatusCode?: number;
message?: string;
graphQLErrors?: any[];
response?: Response;
}

export interface GQLExtensions {
Expand Down
1 change: 1 addition & 0 deletions packages/storefront-api-client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ const client = createStorefrontApiClient({
| networkStatusCode? | `number` | HTTP response status code |
| message? | `string` | The provided error message |
| graphQLErrors? | `any[]` | The GraphQL API errors returned by the server |
| response? | `Response` | The raw response object from the network fetch call |

### Client `request()` response examples

Expand Down

0 comments on commit 1c4f8de

Please sign in to comment.