Skip to content

Commit ddb99ed

Browse files
committed
Fix and improve types.
1 parent 254fe46 commit ddb99ed

3 files changed

Lines changed: 52 additions & 37 deletions

File tree

changelog.md

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

33
## Next
44

5+
### Major
6+
7+
- Renamed the type `FetchGraphQLResultErrors` to `FetchGraphQLResultError` in `fetchGraphQL.mjs`.
8+
9+
### Minor
10+
11+
- Added a new `FetchGraphQLResultErrorLoading` to `fetchGraphQL.mjs` containing the GraphQL result error types related to loading that are generated on the client, not the GraphQL server.
12+
513
### Patch
614

715
- Updated dev dependencies.
816
- Simplified dev dependencies and config for ESLint.
17+
- Fixed issues with GraphQL result related types from `types.mjs`.
18+
- Improved various JSDoc descriptions.
919

1020
## 17.0.0
1121

fetchGraphQL.mjs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ const ERROR_CODE_RESPONSE_MALFORMED = "RESPONSE_MALFORMED";
1111
/**
1212
* Fetches a GraphQL operation, always resolving a
1313
* {@link GraphQLResult GraphQL result} suitable for use as a
14-
* {@link CacheValue cache value}, even if there are errors.
14+
* {@link CacheValue cache value}, even if there are
15+
* {@link FetchGraphQLResultError errors}.
1516
* @param {string} fetchUri Fetch URI for the GraphQL API.
1617
* @param {RequestInit} [fetchOptions] Fetch options.
1718
* @returns {Promise<FetchGraphQLResult>} Resolves a result suitable for use as
@@ -25,7 +26,7 @@ export default function fetchGraphQL(fetchUri, fetchOptions) {
2526
/** @type {FetchGraphQLResult} */
2627
const result = {};
2728

28-
/** @type {Array<FetchGraphQLResultErrors>} */
29+
/** @type {Array<FetchGraphQLResultError>} */
2930
const resultErrors = [];
3031

3132
const fetcher =
@@ -164,19 +165,25 @@ export default function fetchGraphQL(fetchUri, fetchOptions) {
164165
}
165166

166167
/**
167-
* {@link GraphQLResult GraphQL result} when using {@linkcode fetchGraphQL}.
168+
* {@linkcode fetchGraphQL} {@link GraphQLResult GraphQL result}.
168169
* @typedef {import("./types.mjs").GraphQLResult<
169-
* FetchGraphQLResultErrors
170+
* FetchGraphQLResultError
170171
* >} FetchGraphQLResult
171172
*/
172173

173174
/**
174-
* {@link GraphQLResult.errors GraphQL result errors} that are possible when
175-
* using {@linkcode fetchGraphQL}.
176-
* @typedef {import("./types.mjs").GraphQLResultError
177-
* | import("./types.mjs").GraphQLResultErrorLoadingFetch
175+
* {@linkcode fetchGraphQL} {@link GraphQLResult.errors GraphQL result error}.
176+
* @typedef {FetchGraphQLResultErrorLoading
177+
* | import("./types.mjs").GraphQLResultError
178+
* } FetchGraphQLResultError
179+
*/
180+
181+
/**
182+
* {@linkcode fetchGraphQL} {@link GraphQLResult.errors GraphQL result error}
183+
* that’s generated on the client, not the GraphQL server.
184+
* @typedef {import("./types.mjs").GraphQLResultErrorLoadingFetch
178185
* | import("./types.mjs").GraphQLResultErrorResponseHttpStatus
179186
* | import("./types.mjs").GraphQLResultErrorResponseJsonParse
180187
* | import("./types.mjs").GraphQLResultErrorResponseMalformed
181-
* } FetchGraphQLResultErrors
188+
* } FetchGraphQLResultErrorLoading
182189
*/

types.mjs

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export {};
2828
/**
2929
* A GraphQL result.
3030
* @see [GraphQL spec for a response](https://spec.graphql.org/October2021/#sec-Response).
31-
* @template [ErrorTypes=GraphQLResultError]
31+
* @template [ErrorTypes=GraphQLResultError] Possible error types.
3232
* @typedef {object} GraphQLResult
3333
* @prop {Response} [response] The GraphQL server response. Non-enumerable to
3434
* prevent it from serializing to JSON when sending SSR cache to the client
@@ -39,45 +39,41 @@ export {};
3939
*/
4040

4141
/**
42-
* A {@link GraphQLResult.errors GraphQL result error}; either created by the
43-
* GraphQL server, or by whatever loaded the GraphQL on the client (e.g.
44-
* {@linkcode fetchGraphQL}).
42+
* A {@link GraphQLResult.errors GraphQL result error}.
4543
* @see [GraphQL spec for response errors](https://spec.graphql.org/October2021/#sec-Errors).
46-
* @template [Extensions=Record<string, unknown>] Custom error data.
44+
* @template {Record<string, unknown>} [Extensions=Record<string, unknown>]
45+
* Extensions to a standard GraphQL error.
4746
* @typedef {object} GraphQLResultError
4847
* @prop {string} message Error message.
4948
* @prop {Array<{ line: number; column: number }>} [locations] GraphQL query
5049
* locations related to the error.
5150
* @prop {Array<string | number>} [path] GraphQL result
5251
* {@link GraphQLResult.data `data`} property path related to the error.
53-
* @prop {Extensions} [extensions] Custom error data. If the error was created
54-
* on the client and not the GraphQL server, this property should be present
55-
* and contain at least `client: true`, although `code` and error specific
56-
* properties may be present.
52+
* @prop {Extensions} [extensions] Extensions to a standard GraphQL error.
5753
*/
5854

5955
/**
60-
* A {@link GraphQLResult GraphQL result} loading error generated by the client,
56+
* A {@link GraphQLResult GraphQL result} loading error generated on the client,
6157
* not the GraphQL server.
62-
* @template {string} Code
63-
* @template [Extensions={}]
64-
* @typedef {Pick<
65-
* GraphQLResultError<GraphQLResultErrorLoadingMeta & Extensions>,
66-
* "message" | "extensions"
67-
* >} GraphQLResultErrorLoading
68-
*
58+
* @template {string} Code Error code.
59+
* @template {Record<string, unknown>} [Extensions={}] Error specific details.
60+
* @typedef {object} GraphQLResultErrorLoading
61+
* @prop {string} message Error message.
62+
* @prop {GraphQLResultErrorLoadingMeta<Code> & Extensions} extensions Error
63+
* specific details.
6964
*/
7065

7166
/**
67+
* @template {string} Code Error code.
7268
* @typedef {object} GraphQLResultErrorLoadingMeta
73-
* @prop {true} client Indicates that this error was generated by the client and
74-
* wasn’t present in the GraphQL response.
75-
* @prop {string} code Error code.
69+
* @prop {true} client Error was generated on the client, not the GraphQL
70+
* server.
71+
* @prop {Code} code Error code.
7672
*/
7773

7874
/**
79-
* The GraphQL request had a fetch error, e.g. the `fetch` global isn’t defined,
80-
* or the network is offline.
75+
* {@link GraphQLResultError GraphQL error} that the GraphQL request had a fetch
76+
* error, e.g. the `fetch` global isn’t defined, or the network is offline.
8177
* @typedef {GraphQLResultErrorLoading<
8278
* "FETCH_ERROR",
8379
* GraphQLResultErrorLoadingFetchDetails
@@ -90,8 +86,8 @@ export {};
9086
*/
9187

9288
/**
93-
* The GraphQL request had a fetch error, e.g. the `fetch` global isn’t defined,
94-
* or the network is offline.
89+
* {@link GraphQLResultError GraphQL error} that the GraphQL response had an
90+
* error HTTP status.
9591
* @typedef {GraphQLResultErrorLoading<
9692
* "RESPONSE_HTTP_STATUS",
9793
* GraphQLResultErrorResponseHttpStatusDetails
@@ -105,7 +101,8 @@ export {};
105101
*/
106102

107103
/**
108-
* The GraphQL response JSON had a parse error.
104+
* {@link GraphQLResultError GraphQL error} that the GraphQL response JSON had a
105+
* parse error.
109106
* @typedef {GraphQLResultErrorLoading<
110107
* "RESPONSE_JSON_PARSE_ERROR",
111108
* GraphQLResultErrorResponseJsonParseDetails
@@ -118,9 +115,10 @@ export {};
118115
*/
119116

120117
/**
121-
* The GraphQL response JSON was malformed because it wasn’t an object, was
122-
* missing an `errors` or `data` property, the `errors` property wasn’t an
123-
* array, or the `data` property wasn’t an object or `null`.
118+
* {@link GraphQLResultError GraphQL error} that the GraphQL response JSON was
119+
* malformed because it wasn’t an object, was missing an `errors` or `data`
120+
* property, the `errors` property wasn’t an array, or the `data` property
121+
* wasn’t an object or `null`.
124122
* @typedef {GraphQLResultErrorLoading<
125123
* "RESPONSE_MALFORMED"
126124
* >} GraphQLResultErrorResponseMalformed

0 commit comments

Comments
 (0)