1
1
// @ts -check
2
2
3
+ /**
4
+ * @import { CacheValue } from "./Cache.mjs"
5
+ * @import {
6
+ * GraphQLResult,
7
+ * GraphQLResultError,
8
+ * GraphQLResultErrorLoadingFetch,
9
+ * GraphQLResultErrorResponseHttpStatus,
10
+ * GraphQLResultErrorResponseJsonParse,
11
+ * GraphQLResultErrorResponseMalformed,
12
+ * } from "./types.mjs"
13
+ */
14
+
3
15
const ERROR_CODE_FETCH_ERROR = "FETCH_ERROR" ;
4
16
const ERROR_CODE_RESPONSE_HTTP_STATUS = "RESPONSE_HTTP_STATUS" ;
5
17
const ERROR_CODE_RESPONSE_JSON_PARSE_ERROR = "RESPONSE_JSON_PARSE_ERROR" ;
6
18
const ERROR_CODE_RESPONSE_MALFORMED = "RESPONSE_MALFORMED" ;
7
19
8
- /** @typedef {import("./Cache.mjs").CacheValue } CacheValue */
9
- /** @typedef {import("./types.mjs").GraphQLResult } GraphQLResult */
10
-
11
20
/**
12
21
* Fetches a GraphQL operation, always resolving a
13
22
* {@link GraphQLResult GraphQL result} suitable for use as a
@@ -45,7 +54,7 @@ export default function fetchGraphQL(fetchUri, fetchOptions) {
45
54
46
55
if ( ! response . ok )
47
56
resultErrors . push (
48
- /** @type {import("./types.mjs"). GraphQLResultErrorResponseHttpStatus } */ ( {
57
+ /** @type {GraphQLResultErrorResponseHttpStatus } */ ( {
49
58
message : `HTTP ${ response . status } status.` ,
50
59
extensions : {
51
60
client : true ,
@@ -65,7 +74,7 @@ export default function fetchGraphQL(fetchUri, fetchOptions) {
65
74
66
75
if ( typeof json !== "object" || ! json || Array . isArray ( json ) )
67
76
resultErrors . push (
68
- /** @type {import("./types.mjs"). GraphQLResultErrorResponseMalformed }*/ ( {
77
+ /** @type {GraphQLResultErrorResponseMalformed }*/ ( {
69
78
message : "Response JSON isn’t an object." ,
70
79
extensions : {
71
80
client : true ,
@@ -79,7 +88,7 @@ export default function fetchGraphQL(fetchUri, fetchOptions) {
79
88
80
89
if ( ! hasErrors && ! hasData )
81
90
resultErrors . push (
82
- /** @type {import("./types.mjs"). GraphQLResultErrorResponseMalformed }*/ ( {
91
+ /** @type {GraphQLResultErrorResponseMalformed }*/ ( {
83
92
message :
84
93
"Response JSON is missing an `errors` or `data` property." ,
85
94
extensions : {
@@ -94,7 +103,7 @@ export default function fetchGraphQL(fetchUri, fetchOptions) {
94
103
if ( hasErrors )
95
104
if ( ! Array . isArray ( json . errors ) )
96
105
resultErrors . push (
97
- /** @type {import("./types.mjs"). GraphQLResultErrorResponseMalformed }*/ ( {
106
+ /** @type {GraphQLResultErrorResponseMalformed }*/ ( {
98
107
message :
99
108
"Response JSON `errors` property isn’t an array." ,
100
109
extensions : {
@@ -114,7 +123,7 @@ export default function fetchGraphQL(fetchUri, fetchOptions) {
114
123
Array . isArray ( json . data )
115
124
)
116
125
resultErrors . push (
117
- /** @type {import("./types.mjs"). GraphQLResultErrorResponseMalformed }*/ ( {
126
+ /** @type {GraphQLResultErrorResponseMalformed }*/ ( {
118
127
message :
119
128
"Response JSON `data` property isn’t an object or null." ,
120
129
extensions : {
@@ -131,7 +140,7 @@ export default function fetchGraphQL(fetchUri, fetchOptions) {
131
140
// Response JSON parse error.
132
141
( { message } ) => {
133
142
resultErrors . push (
134
- /** @type {import("./types.mjs"). GraphQLResultErrorResponseJsonParse } */ ( {
143
+ /** @type {GraphQLResultErrorResponseJsonParse } */ ( {
135
144
message : "Response JSON parse error." ,
136
145
extensions : {
137
146
client : true ,
@@ -147,7 +156,7 @@ export default function fetchGraphQL(fetchUri, fetchOptions) {
147
156
// Fetch error.
148
157
( { message } ) => {
149
158
resultErrors . push (
150
- /** @type {import("./types.mjs"). GraphQLResultErrorLoadingFetch } */ ( {
159
+ /** @type {GraphQLResultErrorLoadingFetch } */ ( {
151
160
message : "Fetch error." ,
152
161
extensions : {
153
162
client : true ,
@@ -166,24 +175,21 @@ export default function fetchGraphQL(fetchUri, fetchOptions) {
166
175
167
176
/**
168
177
* {@linkcode fetchGraphQL } {@link GraphQLResult GraphQL result }.
169
- * @typedef {import("./types.mjs").GraphQLResult<
170
- * FetchGraphQLResultError
171
- * >} FetchGraphQLResult
178
+ * @typedef {GraphQLResult<FetchGraphQLResultError> } FetchGraphQLResult
172
179
*/
173
180
174
181
/**
175
182
* {@linkcode fetchGraphQL } {@link GraphQLResult.errors GraphQL result error }.
176
183
* @typedef {FetchGraphQLResultErrorLoading
177
- * | import("./types.mjs").GraphQLResultError
178
- * } FetchGraphQLResultError
184
+ * | GraphQLResultError} FetchGraphQLResultError
179
185
*/
180
186
181
187
/**
182
188
* {@linkcode fetchGraphQL } {@link GraphQLResult.errors GraphQL result error }
183
189
* that’s generated on the client, not the GraphQL server.
184
- * @typedef {import("./types.mjs"). GraphQLResultErrorLoadingFetch
185
- * | import("./types.mjs"). GraphQLResultErrorResponseHttpStatus
186
- * | import("./types.mjs"). GraphQLResultErrorResponseJsonParse
187
- * | import("./types.mjs"). GraphQLResultErrorResponseMalformed
190
+ * @typedef {GraphQLResultErrorLoadingFetch
191
+ * | GraphQLResultErrorResponseHttpStatus
192
+ * | GraphQLResultErrorResponseJsonParse
193
+ * | GraphQLResultErrorResponseMalformed
188
194
* } FetchGraphQLResultErrorLoading
189
195
*/
0 commit comments