graphql-http 1.11.0 → 1.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -18,7 +18,7 @@ function serverAudits(opts) {
18
18
  // Media Types
19
19
  (0, utils_1.audit)(
20
20
  // TODO: convert to MUST after watershed
21
- 'SHOULD accept application/graphql-response+json and match the content-type', async () => {
21
+ '22EB', 'SHOULD accept application/graphql-response+json and match the content-type', async () => {
22
22
  const res = await fetchFn(await getUrl(opts.url), {
23
23
  method: 'POST',
24
24
  headers: {
@@ -27,10 +27,12 @@ function serverAudits(opts) {
27
27
  },
28
28
  body: JSON.stringify({ query: '{ __typename }' }),
29
29
  });
30
- (0, utils_1.assert)('Status code', res.status).toBe(200);
31
- (0, utils_1.assert)('Content-Type header', res.headers.get('content-type')).toContain('application/graphql-response+json');
30
+ (0, utils_1.ressert)(res).status.toBe(200);
31
+ (0, utils_1.ressert)(res)
32
+ .header('content-type')
33
+ .toContain('application/graphql-response+json');
32
34
  }),
33
- (0, utils_1.audit)('MUST accept application/json and match the content-type', async () => {
35
+ (0, utils_1.audit)('4655', 'MUST accept application/json and match the content-type', async () => {
34
36
  const res = await fetchFn(await getUrl(opts.url), {
35
37
  method: 'POST',
36
38
  headers: {
@@ -39,10 +41,10 @@ function serverAudits(opts) {
39
41
  },
40
42
  body: JSON.stringify({ query: '{ __typename }' }),
41
43
  });
42
- (0, utils_1.assert)('Status code', res.status).toBe(200);
43
- (0, utils_1.assert)('Content-Type header', res.headers.get('content-type')).toContain('application/json');
44
+ (0, utils_1.ressert)(res).status.toBe(200);
45
+ (0, utils_1.ressert)(res).header('content-type').toContain('application/json');
44
46
  }),
45
- (0, utils_1.audit)('SHOULD accept */* and use application/json for the content-type', async () => {
47
+ (0, utils_1.audit)('47DE', 'SHOULD accept */* and use application/json for the content-type', async () => {
46
48
  const res = await fetchFn(await getUrl(opts.url), {
47
49
  method: 'POST',
48
50
  headers: {
@@ -51,17 +53,17 @@ function serverAudits(opts) {
51
53
  },
52
54
  body: JSON.stringify({ query: '{ __typename }' }),
53
55
  });
54
- (0, utils_1.assert)('Status code', res.status).toBe(200);
55
- (0, utils_1.assert)('Content-Type header', res.headers.get('content-type')).toContain('application/json');
56
+ (0, utils_1.ressert)(res).status.toBe(200);
57
+ (0, utils_1.ressert)(res).header('content-type').toContain('application/json');
56
58
  }),
57
- (0, utils_1.audit)('SHOULD assume application/json content-type when accept is missing', async () => {
59
+ (0, utils_1.audit)('80D8', 'SHOULD assume application/json content-type when accept is missing', async () => {
58
60
  const url = new URL(await getUrl(opts.url));
59
61
  url.searchParams.set('query', '{ __typename }');
60
62
  const res = await fetchFn(url.toString());
61
- (0, utils_1.assert)('Status code', res.status).toBe(200);
62
- (0, utils_1.assert)('Content-Type header', res.headers.get('content-type')).toContain('application/json');
63
+ (0, utils_1.ressert)(res).status.toBe(200);
64
+ (0, utils_1.ressert)(res).header('content-type').toContain('application/json');
63
65
  }),
64
- (0, utils_1.audit)('MUST use utf-8 encoding when responding', async () => {
66
+ (0, utils_1.audit)('82A3', 'MUST use utf-8 encoding when responding', async () => {
65
67
  const res = await fetchFn(await getUrl(opts.url), {
66
68
  method: 'POST',
67
69
  headers: {
@@ -69,28 +71,16 @@ function serverAudits(opts) {
69
71
  },
70
72
  body: JSON.stringify({ query: '{ __typename }' }),
71
73
  });
72
- (0, utils_1.assert)('Status code', res.status).toBe(200);
73
- // has charset set to utf-8
74
- try {
75
- (0, utils_1.assert)('Content-Type header', res.headers.get('content-type')).toContain('charset=utf-8');
76
- return;
77
- }
78
- catch (_a) {
79
- // noop, continue
80
- }
81
- // has no charset specified
82
- (0, utils_1.assert)('Content-Type header', res.headers.get('content-type')).notToContain('charset');
83
- // and the content is utf-8 encoded
74
+ (0, utils_1.ressert)(res).status.toBe(200);
84
75
  try {
85
76
  const decoder = new TextDecoder('utf-8');
86
- const decoded = decoder.decode(await res.arrayBuffer());
87
- (0, utils_1.assert)('UTF-8 decoded body', decoded).toBe('{"data":{"__typename":"Query"}}');
77
+ decoder.decode(await res.arrayBuffer());
88
78
  }
89
- catch (_b) {
90
- throw 'Body is not UTF-8 encoded';
79
+ catch (_a) {
80
+ throw new utils_1.AuditError(res, 'Response body is not UTF-8 encoded');
91
81
  }
92
82
  }),
93
- (0, utils_1.audit)('MUST accept utf-8 encoding', async () => {
83
+ (0, utils_1.audit)('BF61', 'MUST accept utf-8 encoded request', async () => {
94
84
  const res = await fetchFn(await getUrl(opts.url), {
95
85
  method: 'POST',
96
86
  headers: {
@@ -98,10 +88,9 @@ function serverAudits(opts) {
98
88
  },
99
89
  body: JSON.stringify({ query: '{ __typename }' }),
100
90
  });
101
- (0, utils_1.assert)('Status code', res.status).toBe(200);
102
- (0, utils_1.assert)('Content-Type header', res.headers.get('content-type')).toContain('utf-8');
91
+ (0, utils_1.ressert)(res).status.toBe(200);
103
92
  }),
104
- (0, utils_1.audit)('MUST assume utf-8 if encoding is unspecified', async () => {
93
+ (0, utils_1.audit)('78D5', 'MUST assume utf-8 in request if encoding is unspecified', async () => {
105
94
  const res = await fetchFn(await getUrl(opts.url), {
106
95
  method: 'POST',
107
96
  headers: {
@@ -109,27 +98,26 @@ function serverAudits(opts) {
109
98
  },
110
99
  body: JSON.stringify({ query: '{ __typename }' }),
111
100
  });
112
- (0, utils_1.assert)('Status code', res.status).toBe(200);
113
- (0, utils_1.assert)('Content-Type header', res.headers.get('content-type')).toContain('utf-8');
101
+ (0, utils_1.ressert)(res).status.toBe(200);
114
102
  }),
115
103
  // Request
116
- (0, utils_1.audit)('MUST accept POST requests', async () => {
104
+ (0, utils_1.audit)('2C94', 'MUST accept POST requests', async () => {
117
105
  const res = await fetchFn(await getUrl(opts.url), {
118
106
  method: 'POST',
119
107
  headers: { 'content-type': 'application/json' },
120
108
  body: JSON.stringify({ query: '{ __typename }' }),
121
109
  });
122
- (0, utils_1.assert)('Status code', res.status).toBe(200);
110
+ (0, utils_1.ressert)(res).status.toBe(200);
123
111
  }),
124
- (0, utils_1.audit)('MAY accept application/x-www-form-urlencoded formatted GET requests', async () => {
112
+ (0, utils_1.audit)('5A70', 'MAY accept application/x-www-form-urlencoded formatted GET requests', async () => {
125
113
  const url = new URL(await getUrl(opts.url));
126
114
  url.searchParams.set('query', '{ __typename }');
127
115
  const res = await fetchFn(url.toString());
128
- (0, utils_1.assert)('Status code', res.status).toBe(200);
116
+ (0, utils_1.ressert)(res).status.toBe(200);
129
117
  }),
130
118
  // Request GET
131
119
  // TODO: this is a MUST if the server supports GET requests
132
- (0, utils_1.audit)('MAY NOT allow executing mutations on GET requests', async () => {
120
+ (0, utils_1.audit)('9C48', 'MAY NOT allow executing mutations on GET requests', async () => {
133
121
  const url = new URL(await getUrl(opts.url));
134
122
  url.searchParams.set('query', 'mutation { __typename }');
135
123
  const res = await fetchFn(url.toString(), {
@@ -137,40 +125,40 @@ function serverAudits(opts) {
137
125
  accept: 'application/graphql-response+json',
138
126
  },
139
127
  });
140
- (0, utils_1.assert)('Status code', res.status).toBeBetween(400, 499);
128
+ (0, utils_1.ressert)(res).status.toBeBetween(400, 499);
141
129
  }),
142
130
  // Request POST
143
- (0, utils_1.audit)('SHOULD respond with 4xx status code if content-type is not supplied on POST requests', async () => {
131
+ (0, utils_1.audit)('9ABE', 'SHOULD respond with 4xx status code if content-type is not supplied on POST requests', async () => {
144
132
  const res = await fetchFn(await getUrl(opts.url), {
145
133
  method: 'POST',
146
134
  });
147
- (0, utils_1.assert)('Status code', res.status).toBeBetween(400, 499);
135
+ (0, utils_1.ressert)(res).status.toBeBetween(400, 499);
148
136
  }),
149
- (0, utils_1.audit)('MUST accept application/json POST requests', async () => {
137
+ (0, utils_1.audit)('03D4', 'MUST accept application/json POST requests', async () => {
150
138
  const res = await fetchFn(await getUrl(opts.url), {
151
139
  method: 'POST',
152
140
  headers: { 'content-type': 'application/json' },
153
141
  body: JSON.stringify({ query: '{ __typename }' }),
154
142
  });
155
- (0, utils_1.assert)('Status code', res.status).toBe(200);
143
+ (0, utils_1.ressert)(res).status.toBe(200);
156
144
  }),
157
- (0, utils_1.audit)('MUST require a request body on POST', async () => {
145
+ (0, utils_1.audit)('7267', 'MUST require a request body on POST', async () => {
158
146
  var _a;
159
147
  const res = await fetchFn(await getUrl(opts.url), {
160
148
  method: 'POST',
161
149
  headers: { 'content-type': 'application/json' },
162
150
  });
163
151
  if ((_a = res.headers.get('content-type')) === null || _a === void 0 ? void 0 : _a.includes('application/json')) {
164
- (0, utils_1.assert)('Execution result', await (0, utils_1.assertBodyAsExecutionResult)(res)).toHaveProperty('errors');
152
+ await (0, utils_1.ressert)(res).bodyAsExecutionResult.toHaveProperty('errors');
165
153
  }
166
154
  else {
167
- (0, utils_1.assert)('Status code', res.status).toBe(400);
155
+ (0, utils_1.ressert)(res).status.toBe(400);
168
156
  }
169
157
  }),
170
158
  // Request Parameters
171
159
  (0, utils_1.audit)(
172
160
  // TODO: convert to MUST after watershed
173
- 'SHOULD use 400 status code on missing {query} parameter when accepting application/graphql-response+json', async () => {
161
+ '6610', 'SHOULD use 400 status code on missing {query} parameter when accepting application/graphql-response+json', async () => {
174
162
  const res = await fetchFn(await getUrl(opts.url), {
175
163
  method: 'POST',
176
164
  headers: {
@@ -179,9 +167,9 @@ function serverAudits(opts) {
179
167
  },
180
168
  body: JSON.stringify({ notquery: '{ __typename }' }),
181
169
  });
182
- (0, utils_1.assert)('Status code', res.status).toBe(400);
170
+ (0, utils_1.ressert)(res).status.toBe(400);
183
171
  }),
184
- (0, utils_1.audit)('SHOULD use 200 status code with errors field on missing {query} parameter when accepting application/json', async () => {
172
+ (0, utils_1.audit)('3715', 'SHOULD use 200 status code with errors field on missing {query} parameter when accepting application/json', async () => {
185
173
  const res = await fetchFn(await getUrl(opts.url), {
186
174
  method: 'POST',
187
175
  headers: {
@@ -190,10 +178,10 @@ function serverAudits(opts) {
190
178
  },
191
179
  body: JSON.stringify({ notquery: '{ __typename }' }),
192
180
  });
193
- (0, utils_1.assert)('Status code', res.status).toBe(200);
194
- (0, utils_1.assert)('Execution result', await (0, utils_1.assertBodyAsExecutionResult)(res)).toHaveProperty('errors');
181
+ (0, utils_1.ressert)(res).status.toBe(200);
182
+ await (0, utils_1.ressert)(res).bodyAsExecutionResult.toHaveProperty('errors');
195
183
  }),
196
- ...[{ obj: 'ect' }, 0, false, ['array']].map((invalid) => (0, utils_1.audit)(
184
+ ...[{ obj: 'ect' }, 0, false, ['array']].map((invalid, index) => (0, utils_1.audit)(`4F5${index}`,
197
185
  // TODO: convert to MUST after watershed
198
186
  `SHOULD use 400 status code on ${(0, utils_1.extendedTypeof)(invalid)} {query} parameter when accepting application/graphql-response+json`, async () => {
199
187
  const res = await fetchFn(await getUrl(opts.url), {
@@ -206,9 +194,9 @@ function serverAudits(opts) {
206
194
  query: invalid,
207
195
  }),
208
196
  });
209
- (0, utils_1.assert)('Status code', res.status).toBe(400);
197
+ (0, utils_1.ressert)(res).status.toBe(400);
210
198
  })),
211
- ...[{ obj: 'ect' }, 0, false, ['array']].map((invalid) => (0, utils_1.audit)(`SHOULD use 200 status code with errors field on ${(0, utils_1.extendedTypeof)(invalid)} {query} parameter when accepting application/json`, async () => {
199
+ ...[{ obj: 'ect' }, 0, false, ['array']].map((invalid, index) => (0, utils_1.audit)(`9FE${index}`, `SHOULD use 200 status code with errors field on ${(0, utils_1.extendedTypeof)(invalid)} {query} parameter when accepting application/json`, async () => {
212
200
  const res = await fetchFn(await getUrl(opts.url), {
213
201
  method: 'POST',
214
202
  headers: {
@@ -219,12 +207,12 @@ function serverAudits(opts) {
219
207
  query: invalid,
220
208
  }),
221
209
  });
222
- (0, utils_1.assert)('Status code', res.status).toBe(200);
223
- (0, utils_1.assert)('Execution result', await (0, utils_1.assertBodyAsExecutionResult)(res)).toHaveProperty('errors');
210
+ (0, utils_1.ressert)(res).status.toBe(200);
211
+ await (0, utils_1.ressert)(res).bodyAsExecutionResult.toHaveProperty('errors');
224
212
  })),
225
213
  (0, utils_1.audit)(
226
214
  // TODO: convert to MUST after watershed
227
- 'SHOULD allow string {query} parameter when accepting application/graphql-response+json', async () => {
215
+ '34A2', 'SHOULD allow string {query} parameter when accepting application/graphql-response+json', async () => {
228
216
  const res = await fetchFn(await getUrl(opts.url), {
229
217
  method: 'POST',
230
218
  headers: {
@@ -235,9 +223,9 @@ function serverAudits(opts) {
235
223
  query: '{ __typename }',
236
224
  }),
237
225
  });
238
- (0, utils_1.assert)('Status code', res.status).toBe(200);
226
+ (0, utils_1.ressert)(res).status.toBe(200);
239
227
  }),
240
- (0, utils_1.audit)('MUST allow string {query} parameter when accepting application/json', async () => {
228
+ (0, utils_1.audit)('13EE', 'MUST allow string {query} parameter when accepting application/json', async () => {
241
229
  const res = await fetchFn(await getUrl(opts.url), {
242
230
  method: 'POST',
243
231
  headers: {
@@ -248,10 +236,10 @@ function serverAudits(opts) {
248
236
  query: '{ __typename }',
249
237
  }),
250
238
  });
251
- (0, utils_1.assert)('Status code', res.status).toBe(200);
252
- (0, utils_1.assert)('Execution result', await (0, utils_1.assertBodyAsExecutionResult)(res)).notToHaveProperty('errors');
239
+ (0, utils_1.ressert)(res).status.toBe(200);
240
+ await (0, utils_1.ressert)(res).bodyAsExecutionResult.notToHaveProperty('errors');
253
241
  }),
254
- ...[{ obj: 'ect' }, 0, false, ['array']].map((invalid) => (0, utils_1.audit)(
242
+ ...[{ obj: 'ect' }, 0, false, ['array']].map((invalid, index) => (0, utils_1.audit)(`E3E${index}`,
255
243
  // TODO: convert to MUST after watershed
256
244
  `SHOULD use 400 status code on ${(0, utils_1.extendedTypeof)(invalid)} {operationName} parameter when accepting application/graphql-response+json`, async () => {
257
245
  const res = await fetchFn(await getUrl(opts.url), {
@@ -265,9 +253,9 @@ function serverAudits(opts) {
265
253
  query: '{ __typename }',
266
254
  }),
267
255
  });
268
- (0, utils_1.assert)('Status code', res.status).toBe(400);
256
+ (0, utils_1.ressert)(res).status.toBe(400);
269
257
  })),
270
- ...[{ obj: 'ect' }, 0, false, ['array']].map((invalid) => (0, utils_1.audit)(`SHOULD use 200 status code with errors field on ${(0, utils_1.extendedTypeof)(invalid)} {operationName} parameter when accepting application/json`, async () => {
258
+ ...[{ obj: 'ect' }, 0, false, ['array']].map((invalid, index) => (0, utils_1.audit)(`FB9${index}`, `SHOULD use 200 status code with errors field on ${(0, utils_1.extendedTypeof)(invalid)} {operationName} parameter when accepting application/json`, async () => {
271
259
  const res = await fetchFn(await getUrl(opts.url), {
272
260
  method: 'POST',
273
261
  headers: {
@@ -279,12 +267,12 @@ function serverAudits(opts) {
279
267
  query: '{ __typename }',
280
268
  }),
281
269
  });
282
- (0, utils_1.assert)('Status code', res.status).toBe(200);
283
- (0, utils_1.assert)('Execution result', await (0, utils_1.assertBodyAsExecutionResult)(res)).toHaveProperty('errors');
270
+ (0, utils_1.ressert)(res).status.toBe(200);
271
+ await (0, utils_1.ressert)(res).bodyAsExecutionResult.toHaveProperty('errors');
284
272
  })),
285
273
  (0, utils_1.audit)(
286
274
  // TODO: convert to MUST after watershed
287
- 'SHOULD allow string {operationName} parameter when accepting application/graphql-response+json', async () => {
275
+ '8161', 'SHOULD allow string {operationName} parameter when accepting application/graphql-response+json', async () => {
288
276
  const res = await fetchFn(await getUrl(opts.url), {
289
277
  method: 'POST',
290
278
  headers: {
@@ -296,9 +284,9 @@ function serverAudits(opts) {
296
284
  query: 'query Query { __typename }',
297
285
  }),
298
286
  });
299
- (0, utils_1.assert)('Status code', res.status).toBe(200);
287
+ (0, utils_1.ressert)(res).status.toBe(200);
300
288
  }),
301
- (0, utils_1.audit)('MUST allow string {operationName} parameter when accepting application/json', async () => {
289
+ (0, utils_1.audit)('B8B3', 'MUST allow string {operationName} parameter when accepting application/json', async () => {
302
290
  const res = await fetchFn(await getUrl(opts.url), {
303
291
  method: 'POST',
304
292
  headers: {
@@ -310,11 +298,11 @@ function serverAudits(opts) {
310
298
  query: 'query Query { __typename }',
311
299
  }),
312
300
  });
313
- (0, utils_1.assert)('Status code', res.status).toBe(200);
314
- (0, utils_1.assert)('Execution result', await (0, utils_1.assertBodyAsExecutionResult)(res)).notToHaveProperty('errors');
301
+ (0, utils_1.ressert)(res).status.toBe(200);
302
+ await (0, utils_1.ressert)(res).bodyAsExecutionResult.notToHaveProperty('errors');
315
303
  }),
316
- ...['variables', 'operationName', 'extensions'].flatMap((parameter) => [
317
- (0, utils_1.audit)(
304
+ ...['variables', 'operationName', 'extensions'].flatMap((parameter, index) => [
305
+ (0, utils_1.audit)(`94B${index}`,
318
306
  // TODO: convert to MUST after watershed
319
307
  `SHOULD allow null {${parameter}} parameter when accepting application/graphql-response+json`, async () => {
320
308
  const res = await fetchFn(await getUrl(opts.url), {
@@ -328,10 +316,10 @@ function serverAudits(opts) {
328
316
  [parameter]: null,
329
317
  }),
330
318
  });
331
- (0, utils_1.assert)('Status code', res.status).toBe(200);
332
- (0, utils_1.assert)('Execution result', await (0, utils_1.assertBodyAsExecutionResult)(res)).notToHaveProperty('errors');
319
+ (0, utils_1.ressert)(res).status.toBe(200);
320
+ await (0, utils_1.ressert)(res).bodyAsExecutionResult.notToHaveProperty('errors');
333
321
  }),
334
- (0, utils_1.audit)(`MUST allow null {${parameter}} parameter when accepting application/json`, async () => {
322
+ (0, utils_1.audit)(`022${index}`, `MUST allow null {${parameter}} parameter when accepting application/json`, async () => {
335
323
  const res = await fetchFn(await getUrl(opts.url), {
336
324
  method: 'POST',
337
325
  headers: {
@@ -343,11 +331,11 @@ function serverAudits(opts) {
343
331
  [parameter]: null,
344
332
  }),
345
333
  });
346
- (0, utils_1.assert)('Status code', res.status).toBe(200);
347
- (0, utils_1.assert)('Execution result', await (0, utils_1.assertBodyAsExecutionResult)(res)).notToHaveProperty('errors');
334
+ (0, utils_1.ressert)(res).status.toBe(200);
335
+ await (0, utils_1.ressert)(res).bodyAsExecutionResult.notToHaveProperty('errors');
348
336
  }),
349
337
  ]),
350
- ...['string', 0, false, ['array']].map((invalid) => (0, utils_1.audit)(
338
+ ...['string', 0, false, ['array']].map((invalid, index) => (0, utils_1.audit)(`69B${index}`,
351
339
  // TODO: convert to MUST after watershed
352
340
  `SHOULD use 400 status code on ${(0, utils_1.extendedTypeof)(invalid)} {variables} parameter when accepting application/graphql-response+json`, async () => {
353
341
  const res = await fetchFn(await getUrl(opts.url), {
@@ -361,9 +349,9 @@ function serverAudits(opts) {
361
349
  variables: invalid,
362
350
  }),
363
351
  });
364
- (0, utils_1.assert)('Status code', res.status).toBe(400);
352
+ (0, utils_1.ressert)(res).status.toBe(400);
365
353
  })),
366
- ...['string', 0, false, ['array']].map((invalid) => (0, utils_1.audit)(`SHOULD use 200 status code with errors field on ${(0, utils_1.extendedTypeof)(invalid)} {variables} parameter when accepting application/json`, async () => {
354
+ ...['string', 0, false, ['array']].map((invalid, index) => (0, utils_1.audit)(`F05${index}`, `SHOULD use 200 status code with errors field on ${(0, utils_1.extendedTypeof)(invalid)} {variables} parameter when accepting application/json`, async () => {
367
355
  const res = await fetchFn(await getUrl(opts.url), {
368
356
  method: 'POST',
369
357
  headers: {
@@ -375,12 +363,12 @@ function serverAudits(opts) {
375
363
  variables: invalid,
376
364
  }),
377
365
  });
378
- (0, utils_1.assert)('Status code', res.status).toBe(200);
379
- (0, utils_1.assert)('Execution result', await (0, utils_1.assertBodyAsExecutionResult)(res)).toHaveProperty('errors');
366
+ (0, utils_1.ressert)(res).status.toBe(200);
367
+ await (0, utils_1.ressert)(res).bodyAsExecutionResult.toHaveProperty('errors');
380
368
  })),
381
369
  (0, utils_1.audit)(
382
370
  // TODO: convert to MUST after watershed
383
- 'SHOULD allow map {variables} parameter when accepting application/graphql-response+json', async () => {
371
+ '2EA1', 'SHOULD allow map {variables} parameter when accepting application/graphql-response+json', async () => {
384
372
  const res = await fetchFn(await getUrl(opts.url), {
385
373
  method: 'POST',
386
374
  headers: {
@@ -392,9 +380,9 @@ function serverAudits(opts) {
392
380
  variables: { name: 'sometype' },
393
381
  }),
394
382
  });
395
- (0, utils_1.assert)('Status code', res.status).toBe(200);
383
+ (0, utils_1.ressert)(res).status.toBe(200);
396
384
  }),
397
- (0, utils_1.audit)('MUST allow map {variables} parameter when accepting application/json', async () => {
385
+ (0, utils_1.audit)('28B9', 'MUST allow map {variables} parameter when accepting application/json', async () => {
398
386
  const res = await fetchFn(await getUrl(opts.url), {
399
387
  method: 'POST',
400
388
  headers: {
@@ -406,10 +394,10 @@ function serverAudits(opts) {
406
394
  variables: { name: 'sometype' },
407
395
  }),
408
396
  });
409
- (0, utils_1.assert)('Status code', res.status).toBe(200);
410
- (0, utils_1.assert)('Execution result', await (0, utils_1.assertBodyAsExecutionResult)(res)).notToHaveProperty('errors');
397
+ (0, utils_1.ressert)(res).status.toBe(200);
398
+ await (0, utils_1.ressert)(res).bodyAsExecutionResult.notToHaveProperty('errors');
411
399
  }),
412
- (0, utils_1.audit)('MAY allow URL-encoded JSON string {variables} parameter in GETs when accepting application/graphql-response+json', async () => {
400
+ (0, utils_1.audit)('D6D5', 'MAY allow URL-encoded JSON string {variables} parameter in GETs when accepting application/graphql-response+json', async () => {
413
401
  const url = new URL(await getUrl(opts.url));
414
402
  url.searchParams.set('query', 'query Type($name: String!) { __type(name: $name) { name } }');
415
403
  url.searchParams.set('variables', JSON.stringify({ name: 'sometype' }));
@@ -419,9 +407,9 @@ function serverAudits(opts) {
419
407
  accept: 'application/graphql-response+json',
420
408
  },
421
409
  });
422
- (0, utils_1.assert)('Status code', res.status).toBe(200);
410
+ (0, utils_1.ressert)(res).status.toBe(200);
423
411
  }),
424
- (0, utils_1.audit)('MAY allow URL-encoded JSON string {variables} parameter in GETs when accepting application/json', async () => {
412
+ (0, utils_1.audit)('6A70', 'MAY allow URL-encoded JSON string {variables} parameter in GETs when accepting application/json', async () => {
425
413
  const url = new URL(await getUrl(opts.url));
426
414
  url.searchParams.set('query', 'query Type($name: String!) { __type(name: $name) { name } }');
427
415
  url.searchParams.set('variables', JSON.stringify({ name: 'sometype' }));
@@ -431,10 +419,10 @@ function serverAudits(opts) {
431
419
  accept: 'application/json',
432
420
  },
433
421
  });
434
- (0, utils_1.assert)('Status code', res.status).toBe(200);
435
- (0, utils_1.assert)('Execution result', await (0, utils_1.assertBodyAsExecutionResult)(res)).notToHaveProperty('errors');
422
+ (0, utils_1.ressert)(res).status.toBe(200);
423
+ await (0, utils_1.ressert)(res).bodyAsExecutionResult.notToHaveProperty('errors');
436
424
  }),
437
- ...['string', 0, false, ['array']].map((invalid) => (0, utils_1.audit)(
425
+ ...['string', 0, false, ['array']].map((invalid, index) => (0, utils_1.audit)(`904${index}`,
438
426
  // TODO: convert to MUST after watershed
439
427
  `SHOULD use 400 status code on ${(0, utils_1.extendedTypeof)(invalid)} {extensions} parameter when accepting application/graphql-response+json`, async () => {
440
428
  const res = await fetchFn(await getUrl(opts.url), {
@@ -448,9 +436,9 @@ function serverAudits(opts) {
448
436
  extensions: invalid,
449
437
  }),
450
438
  });
451
- (0, utils_1.assert)('Status code', res.status).toBe(400);
439
+ (0, utils_1.ressert)(res).status.toBe(400);
452
440
  })),
453
- ...['string', 0, false, ['array']].map((invalid) => (0, utils_1.audit)(`SHOULD use 200 status code with errors field on ${(0, utils_1.extendedTypeof)(invalid)} {extensions} parameter when accepting application/json`, async () => {
441
+ ...['string', 0, false, ['array']].map((invalid, index) => (0, utils_1.audit)(`368${index}`, `SHOULD use 200 status code with errors field on ${(0, utils_1.extendedTypeof)(invalid)} {extensions} parameter when accepting application/json`, async () => {
454
442
  const res = await fetchFn(await getUrl(opts.url), {
455
443
  method: 'POST',
456
444
  headers: {
@@ -462,12 +450,12 @@ function serverAudits(opts) {
462
450
  extensions: invalid,
463
451
  }),
464
452
  });
465
- (0, utils_1.assert)('Status code', res.status).toBe(200);
466
- (0, utils_1.assert)('Execution result', await (0, utils_1.assertBodyAsExecutionResult)(res)).toHaveProperty('errors');
453
+ (0, utils_1.ressert)(res).status.toBe(200);
454
+ await (0, utils_1.ressert)(res).bodyAsExecutionResult.toHaveProperty('errors');
467
455
  })),
468
456
  (0, utils_1.audit)(
469
457
  // TODO: convert to MUST after watershed
470
- 'SHOULD allow map {extensions} parameter when accepting application/graphql-response+json', async () => {
458
+ '428F', 'SHOULD allow map {extensions} parameter when accepting application/graphql-response+json', async () => {
471
459
  const res = await fetchFn(await getUrl(opts.url), {
472
460
  method: 'POST',
473
461
  headers: {
@@ -479,9 +467,9 @@ function serverAudits(opts) {
479
467
  extensions: { some: 'value' },
480
468
  }),
481
469
  });
482
- (0, utils_1.assert)('Status code', res.status).toBe(200);
470
+ (0, utils_1.ressert)(res).status.toBe(200);
483
471
  }),
484
- (0, utils_1.audit)('MUST allow map {extensions} parameter when accepting application/json', async () => {
472
+ (0, utils_1.audit)('1B7A', 'MUST allow map {extensions} parameter when accepting application/json', async () => {
485
473
  const res = await fetchFn(await getUrl(opts.url), {
486
474
  method: 'POST',
487
475
  headers: {
@@ -493,12 +481,12 @@ function serverAudits(opts) {
493
481
  extensions: { some: 'value' },
494
482
  }),
495
483
  });
496
- (0, utils_1.assert)('Status code', res.status).toBe(200);
497
- (0, utils_1.assert)('Execution result', await (0, utils_1.assertBodyAsExecutionResult)(res)).notToHaveProperty('errors');
484
+ (0, utils_1.ressert)(res).status.toBe(200);
485
+ await (0, utils_1.ressert)(res).bodyAsExecutionResult.notToHaveProperty('errors');
498
486
  }),
499
- // TODO: audit('MUST accept a map for the {extensions} parameter'),
487
+ // TODO: audit('39AA', 'MUST accept a map for the {extensions} parameter'),
500
488
  // Response application/json
501
- (0, utils_1.audit)('SHOULD use 200 status code on JSON parsing failure when accepting application/json', async () => {
489
+ (0, utils_1.audit)('D477', 'SHOULD use 200 status code on JSON parsing failure when accepting application/json', async () => {
502
490
  const res = await fetchFn(await getUrl(opts.url), {
503
491
  method: 'POST',
504
492
  headers: {
@@ -507,9 +495,9 @@ function serverAudits(opts) {
507
495
  },
508
496
  body: '{ "not a JSON',
509
497
  });
510
- (0, utils_1.assert)('Status code', res.status).toBe(200);
498
+ (0, utils_1.ressert)(res).status.toBe(200);
511
499
  }),
512
- (0, utils_1.audit)('SHOULD use 200 status code if parameters are invalid when accepting application/json', async () => {
500
+ (0, utils_1.audit)('F5AF', 'SHOULD use 200 status code if parameters are invalid when accepting application/json', async () => {
513
501
  const res = await fetchFn(await getUrl(opts.url), {
514
502
  method: 'POST',
515
503
  headers: {
@@ -520,9 +508,9 @@ function serverAudits(opts) {
520
508
  qeury: /* typo */ '{ __typename }',
521
509
  }),
522
510
  });
523
- (0, utils_1.assert)('Status code', res.status).toBe(200);
511
+ (0, utils_1.ressert)(res).status.toBe(200);
524
512
  }),
525
- (0, utils_1.audit)('SHOULD use 200 status code on document parsing failure when accepting application/json', async () => {
513
+ (0, utils_1.audit)('572B', 'SHOULD use 200 status code on document parsing failure when accepting application/json', async () => {
526
514
  const res = await fetchFn(await getUrl(opts.url), {
527
515
  method: 'POST',
528
516
  headers: {
@@ -531,9 +519,9 @@ function serverAudits(opts) {
531
519
  },
532
520
  body: JSON.stringify({ query: '{' }),
533
521
  });
534
- (0, utils_1.assert)('Status code', res.status).toBe(200);
522
+ (0, utils_1.ressert)(res).status.toBe(200);
535
523
  }),
536
- (0, utils_1.audit)('SHOULD use 200 status code on document validation failure when accepting application/json', async () => {
524
+ (0, utils_1.audit)('FDE2', 'SHOULD use 200 status code on document validation failure when accepting application/json', async () => {
537
525
  const res = await fetchFn(await getUrl(opts.url), {
538
526
  method: 'POST',
539
527
  headers: {
@@ -544,23 +532,12 @@ function serverAudits(opts) {
544
532
  query: '{ 8f31403dfe404bccbb0e835f2629c6a7 }', // making sure the field doesnt exist
545
533
  }),
546
534
  });
547
- (0, utils_1.assert)('Status code', res.status).toBe(200);
535
+ (0, utils_1.ressert)(res).status.toBe(200);
548
536
  }),
549
537
  // Response application/graphql-response+json
550
538
  (0, utils_1.audit)(
551
539
  // TODO: convert to MUST after watershed
552
- 'SHOULD use 4xx or 5xx status codes on JSON parsing failure when accepting application/graphql-response+json', async () => {
553
- const res = await fetchFn(await getUrl(opts.url), {
554
- method: 'POST',
555
- headers: {
556
- 'content-type': 'application/json',
557
- accept: 'application/graphql-response+json',
558
- },
559
- body: '{ "not a JSON',
560
- });
561
- (0, utils_1.assert)('Status code', res.status).toBeBetween(400, 499);
562
- }),
563
- (0, utils_1.audit)('SHOULD use 400 status code on JSON parsing failure when accepting application/graphql-response+json', async () => {
540
+ '60AA', 'SHOULD use 4xx or 5xx status codes on JSON parsing failure when accepting application/graphql-response+json', async () => {
564
541
  const res = await fetchFn(await getUrl(opts.url), {
565
542
  method: 'POST',
566
543
  headers: {
@@ -569,9 +546,9 @@ function serverAudits(opts) {
569
546
  },
570
547
  body: '{ "not a JSON',
571
548
  });
572
- (0, utils_1.assert)('Status code', res.status).toBe(400);
549
+ (0, utils_1.ressert)(res).status.toBeBetween(400, 499);
573
550
  }),
574
- (0, utils_1.audit)('SHOULD not contain the data entry on JSON parsing failure when accepting application/graphql-response+json', async () => {
551
+ (0, utils_1.audit)('2163', 'SHOULD use 400 status code on JSON parsing failure when accepting application/graphql-response+json', async () => {
575
552
  const res = await fetchFn(await getUrl(opts.url), {
576
553
  method: 'POST',
577
554
  headers: {
@@ -580,11 +557,11 @@ function serverAudits(opts) {
580
557
  },
581
558
  body: '{ "not a JSON',
582
559
  });
583
- (0, utils_1.assert)('Data entry', (await (0, utils_1.assertBodyAsExecutionResult)(res)).data).toBe(undefined);
560
+ (0, utils_1.ressert)(res).status.toBe(400);
584
561
  }),
585
562
  (0, utils_1.audit)(
586
563
  // TODO: convert to MUST after watershed
587
- 'SHOULD use 4xx or 5xx status codes if parameters are invalid when accepting application/graphql-response+json', async () => {
564
+ '3E36', 'SHOULD use 4xx or 5xx status codes if parameters are invalid when accepting application/graphql-response+json', async () => {
588
565
  const res = await fetchFn(await getUrl(opts.url), {
589
566
  method: 'POST',
590
567
  headers: {
@@ -595,9 +572,9 @@ function serverAudits(opts) {
595
572
  qeury /* typo */: '{ __typename }',
596
573
  }),
597
574
  });
598
- (0, utils_1.assert)('Status code', res.status).toBeBetween(400, 599);
575
+ (0, utils_1.ressert)(res).status.toBeBetween(400, 599);
599
576
  }),
600
- (0, utils_1.audit)('SHOULD use 400 status code if parameters are invalid when accepting application/graphql-response+json', async () => {
577
+ (0, utils_1.audit)('17C5', 'SHOULD use 400 status code if parameters are invalid when accepting application/graphql-response+json', async () => {
601
578
  const res = await fetchFn(await getUrl(opts.url), {
602
579
  method: 'POST',
603
580
  headers: {
@@ -608,9 +585,9 @@ function serverAudits(opts) {
608
585
  qeury: /* typo */ '{ __typename }',
609
586
  }),
610
587
  });
611
- (0, utils_1.assert)('Status code', res.status).toBe(400);
588
+ (0, utils_1.ressert)(res).status.toBe(400);
612
589
  }),
613
- (0, utils_1.audit)('SHOULD not contain the data entry if parameters are invalid when accepting application/graphql-response+json', async () => {
590
+ (0, utils_1.audit)('34D6', 'SHOULD not contain the data entry if parameters are invalid when accepting application/graphql-response+json', async () => {
614
591
  const res = await fetchFn(await getUrl(opts.url), {
615
592
  method: 'POST',
616
593
  headers: {
@@ -621,11 +598,11 @@ function serverAudits(opts) {
621
598
  qeury: /* typo */ '{ __typename }',
622
599
  }),
623
600
  });
624
- (0, utils_1.assert)('Data entry', (await (0, utils_1.assertBodyAsExecutionResult)(res)).data).toBe(undefined);
601
+ await (0, utils_1.ressert)(res).bodyAsExecutionResult.data.toBe(undefined);
625
602
  }),
626
603
  (0, utils_1.audit)(
627
604
  // TODO: convert to MUST after watershed
628
- 'SHOULD use 4xx or 5xx status codes on document parsing failure when accepting application/graphql-response+json', async () => {
605
+ '865D', 'SHOULD use 4xx or 5xx status codes on document parsing failure when accepting application/graphql-response+json', async () => {
629
606
  const res = await fetchFn(await getUrl(opts.url), {
630
607
  method: 'POST',
631
608
  headers: {
@@ -636,9 +613,9 @@ function serverAudits(opts) {
636
613
  query: '{',
637
614
  }),
638
615
  });
639
- (0, utils_1.assert)('Status code', res.status).toBeBetween(400, 599);
616
+ (0, utils_1.ressert)(res).status.toBeBetween(400, 599);
640
617
  }),
641
- (0, utils_1.audit)('SHOULD use 400 status code on document parsing failure when accepting application/graphql-response+json', async () => {
618
+ (0, utils_1.audit)('556A', 'SHOULD use 400 status code on document parsing failure when accepting application/graphql-response+json', async () => {
642
619
  const res = await fetchFn(await getUrl(opts.url), {
643
620
  method: 'POST',
644
621
  headers: {
@@ -649,9 +626,9 @@ function serverAudits(opts) {
649
626
  query: '{',
650
627
  }),
651
628
  });
652
- (0, utils_1.assert)('Status code', res.status).toBe(400);
629
+ (0, utils_1.ressert)(res).status.toBe(400);
653
630
  }),
654
- (0, utils_1.audit)('SHOULD not contain the data entry on document parsing failure when accepting application/graphql-response+json', async () => {
631
+ (0, utils_1.audit)('D586', 'SHOULD not contain the data entry on document parsing failure when accepting application/graphql-response+json', async () => {
655
632
  const res = await fetchFn(await getUrl(opts.url), {
656
633
  method: 'POST',
657
634
  headers: {
@@ -662,11 +639,11 @@ function serverAudits(opts) {
662
639
  query: '{',
663
640
  }),
664
641
  });
665
- (0, utils_1.assert)('Data entry', (await (0, utils_1.assertBodyAsExecutionResult)(res)).data).toBe(undefined);
642
+ await (0, utils_1.ressert)(res).bodyAsExecutionResult.data.toBe(undefined);
666
643
  }),
667
644
  (0, utils_1.audit)(
668
645
  // TODO: convert to MUST after watershed
669
- 'SHOULD use 4xx or 5xx status codes on document validation failure when accepting application/graphql-response+json', async () => {
646
+ '51FE', 'SHOULD use 4xx or 5xx status codes on document validation failure when accepting application/graphql-response+json', async () => {
670
647
  const res = await fetchFn(await getUrl(opts.url), {
671
648
  method: 'POST',
672
649
  headers: {
@@ -677,9 +654,9 @@ function serverAudits(opts) {
677
654
  query: '{ 8f31403dfe404bccbb0e835f2629c6a7 }', // making sure the field doesnt exist
678
655
  }),
679
656
  });
680
- (0, utils_1.assert)('Status code', res.status).toBeBetween(400, 599);
657
+ (0, utils_1.ressert)(res).status.toBeBetween(400, 599);
681
658
  }),
682
- (0, utils_1.audit)('SHOULD use 400 status code on document validation failure when accepting application/graphql-response+json', async () => {
659
+ (0, utils_1.audit)('74FF', 'SHOULD use 400 status code on document validation failure when accepting application/graphql-response+json', async () => {
683
660
  const res = await fetchFn(await getUrl(opts.url), {
684
661
  method: 'POST',
685
662
  headers: {
@@ -690,9 +667,9 @@ function serverAudits(opts) {
690
667
  query: '{ 8f31403dfe404bccbb0e835f2629c6a7 }', // making sure the field doesnt exist
691
668
  }),
692
669
  });
693
- (0, utils_1.assert)('Status code', res.status).toBe(400);
670
+ (0, utils_1.ressert)(res).status.toBe(400);
694
671
  }),
695
- (0, utils_1.audit)('SHOULD not contain the data entry on document validation failure when accepting application/graphql-response+json', async () => {
672
+ (0, utils_1.audit)('5E5B', 'SHOULD not contain the data entry on document validation failure when accepting application/graphql-response+json', async () => {
696
673
  const res = await fetchFn(await getUrl(opts.url), {
697
674
  method: 'POST',
698
675
  headers: {
@@ -703,13 +680,13 @@ function serverAudits(opts) {
703
680
  query: '{ 8f31403dfe404bccbb0e835f2629c6a7 }', // making sure the field doesnt exist
704
681
  }),
705
682
  });
706
- (0, utils_1.assert)('Data entry', (await (0, utils_1.assertBodyAsExecutionResult)(res)).data).toBe(undefined);
683
+ await (0, utils_1.ressert)(res).bodyAsExecutionResult.data.toBe(undefined);
707
684
  }),
708
685
  // TODO: how to fail and have the data entry?
709
- // audit('MUST use 2xx status code if response contains the data entry and it is not null when accepting application/graphql-response+json'),
686
+ // audit('EE52', 'MUST use 2xx status code if response contains the data entry and it is not null when accepting application/graphql-response+json'),
710
687
  // TODO: how to make an unauthorized request?
711
688
  // https://graphql.github.io/graphql-over-http/draft/#sel-EANNNDTAAEVBAAqqc
712
- // audit('SHOULD use 401 or 403 status codes when the request is not permitted')
689
+ // audit('BC58', 'SHOULD use 401 or 403 status codes when the request is not permitted')
713
690
  ];
714
691
  }
715
692
  exports.serverAudits = serverAudits;