graphql-http 1.7.1 → 1.7.2

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.
package/README.md CHANGED
@@ -729,13 +729,13 @@ Having said this, graphql-http is mostly aimed for library authors and simple se
729
729
 
730
730
  If you want a feature-full server with bleeding edge technologies, you're recommended to use one of the following.
731
731
 
732
- | Name | Audit |
733
- | ------------------------------------------------------------------ | -------------------------------------------------------------------- |
734
- | [graphql-yoga](https://www.the-guild.dev/graphql/yoga-server) | [✅ Compliant (0 warnings)](/implementations/graphql-yoga/README.md) |
735
- | [hotchocolate](https://chillicream.com/docs/hotchocolate) | [✅ Compliant (0 warnings)](/implementations/hotchocolate/README.md) |
736
- | [postgraphile](https://www.graphile.org/postgraphile/) | [✅ Compliant](/implementations/postgraphile/README.md) |
737
- | [apollo-server](https://www.apollographql.com/docs/apollo-server/) | [✅ Compliant](/implementations/apollo-server/README.md) |
738
- | [mercurius](https://mercurius.dev) | [✅ Compliant](/implementations/mercurius/README.md) |
732
+ | Name | Audit |
733
+ | ------------------------------------------------------------------ | -------------------------------------------------------- |
734
+ | [graphql-yoga](https://www.the-guild.dev/graphql/yoga-server) | [✅ Compliant](/implementations/graphql-yoga/README.md) |
735
+ | [hotchocolate](https://chillicream.com/docs/hotchocolate) | [✅ Compliant](/implementations/hotchocolate/README.md) |
736
+ | [postgraphile](https://www.graphile.org/postgraphile/) | [✅ Compliant](/implementations/postgraphile/README.md) |
737
+ | [apollo-server](https://www.apollographql.com/docs/apollo-server/) | [✅ Compliant](/implementations/apollo-server/README.md) |
738
+ | [mercurius](https://mercurius.dev) | [✅ Compliant](/implementations/mercurius/README.md) |
739
739
 
740
740
  ## [Documentation](docs/)
741
741
 
@@ -42,9 +42,7 @@ function serverAudits(opts) {
42
42
  (0, utils_1.assert)('Status code', res.status).toBe(200);
43
43
  (0, utils_1.assert)('Content-Type header', res.headers.get('content-type')).toContain('application/json');
44
44
  }),
45
- (0, utils_1.audit)(
46
- // TODO: convert to MUST after watershed
47
- 'SHOULD accept */* and use application/graphql-response+json for the content-type', async () => {
45
+ (0, utils_1.audit)('SHOULD accept */* and use application/json for the content-type', async () => {
48
46
  const res = await fetchFn(opts.url, {
49
47
  method: 'POST',
50
48
  headers: {
@@ -54,20 +52,14 @@ function serverAudits(opts) {
54
52
  body: JSON.stringify({ query: '{ __typename }' }),
55
53
  });
56
54
  (0, utils_1.assert)('Status code', res.status).toBe(200);
57
- (0, utils_1.assert)('Content-Type header', res.headers.get('content-type')).toContain('application/graphql-response+json');
55
+ (0, utils_1.assert)('Content-Type header', res.headers.get('content-type')).toContain('application/json');
58
56
  }),
59
- (0, utils_1.audit)(
60
- // TODO: convert to MUST after watershed
61
- 'SHOULD assume application/graphql-response+json content-type when accept is missing', async () => {
62
- const res = await fetchFn(opts.url, {
63
- method: 'POST',
64
- headers: {
65
- 'content-type': 'application/json',
66
- },
67
- body: JSON.stringify({ query: '{ __typename }' }),
68
- });
57
+ (0, utils_1.audit)('SHOULD assume application/json content-type when accept is missing', async () => {
58
+ const url = new URL(opts.url);
59
+ url.searchParams.set('query', '{ __typename }');
60
+ const res = await fetchFn(url.toString());
69
61
  (0, utils_1.assert)('Status code', res.status).toBe(200);
70
- (0, utils_1.assert)('Content-Type header', res.headers.get('content-type')).toContain('application/graphql-response+json');
62
+ (0, utils_1.assert)('Content-Type header', res.headers.get('content-type')).toContain('application/json');
71
63
  }),
72
64
  (0, utils_1.audit)('MUST use utf-8 encoding when responding', async () => {
73
65
  const res = await fetchFn(opts.url, {
@@ -163,11 +155,17 @@ function serverAudits(opts) {
163
155
  (0, utils_1.assert)('Status code', res.status).toBe(200);
164
156
  }),
165
157
  (0, utils_1.audit)('MUST require a request body on POST', async () => {
158
+ var _a;
166
159
  const res = await fetchFn(opts.url, {
167
160
  method: 'POST',
168
161
  headers: { 'content-type': 'application/json' },
169
162
  });
170
- (0, utils_1.assert)('Status code', res.status).toBe(400);
163
+ 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');
165
+ }
166
+ else {
167
+ (0, utils_1.assert)('Status code', res.status).toBe(400);
168
+ }
171
169
  }),
172
170
  // Request Parameters
173
171
  (0, utils_1.audit)(
@@ -39,9 +39,7 @@ export function serverAudits(opts) {
39
39
  assert('Status code', res.status).toBe(200);
40
40
  assert('Content-Type header', res.headers.get('content-type')).toContain('application/json');
41
41
  }),
42
- audit(
43
- // TODO: convert to MUST after watershed
44
- 'SHOULD accept */* and use application/graphql-response+json for the content-type', async () => {
42
+ audit('SHOULD accept */* and use application/json for the content-type', async () => {
45
43
  const res = await fetchFn(opts.url, {
46
44
  method: 'POST',
47
45
  headers: {
@@ -51,20 +49,14 @@ export function serverAudits(opts) {
51
49
  body: JSON.stringify({ query: '{ __typename }' }),
52
50
  });
53
51
  assert('Status code', res.status).toBe(200);
54
- assert('Content-Type header', res.headers.get('content-type')).toContain('application/graphql-response+json');
52
+ assert('Content-Type header', res.headers.get('content-type')).toContain('application/json');
55
53
  }),
56
- audit(
57
- // TODO: convert to MUST after watershed
58
- 'SHOULD assume application/graphql-response+json content-type when accept is missing', async () => {
59
- const res = await fetchFn(opts.url, {
60
- method: 'POST',
61
- headers: {
62
- 'content-type': 'application/json',
63
- },
64
- body: JSON.stringify({ query: '{ __typename }' }),
65
- });
54
+ audit('SHOULD assume application/json content-type when accept is missing', async () => {
55
+ const url = new URL(opts.url);
56
+ url.searchParams.set('query', '{ __typename }');
57
+ const res = await fetchFn(url.toString());
66
58
  assert('Status code', res.status).toBe(200);
67
- assert('Content-Type header', res.headers.get('content-type')).toContain('application/graphql-response+json');
59
+ assert('Content-Type header', res.headers.get('content-type')).toContain('application/json');
68
60
  }),
69
61
  audit('MUST use utf-8 encoding when responding', async () => {
70
62
  const res = await fetchFn(opts.url, {
@@ -160,11 +152,17 @@ export function serverAudits(opts) {
160
152
  assert('Status code', res.status).toBe(200);
161
153
  }),
162
154
  audit('MUST require a request body on POST', async () => {
155
+ var _a;
163
156
  const res = await fetchFn(opts.url, {
164
157
  method: 'POST',
165
158
  headers: { 'content-type': 'application/json' },
166
159
  });
167
- assert('Status code', res.status).toBe(400);
160
+ if ((_a = res.headers.get('content-type')) === null || _a === void 0 ? void 0 : _a.includes('application/json')) {
161
+ assert('Execution result', await assertBodyAsExecutionResult(res)).toHaveProperty('errors');
162
+ }
163
+ else {
164
+ assert('Status code', res.status).toBe(400);
165
+ }
168
166
  }),
169
167
  // Request Parameters
170
168
  audit(
package/lib/handler.js CHANGED
@@ -296,15 +296,16 @@ function getAcceptableMediaType(acceptHeader) {
296
296
  // TODO: handle the weight parameter "q"
297
297
  const [mediaType, ...params] = accept.split(';');
298
298
  const charset = (params === null || params === void 0 ? void 0 : params.find((param) => param.includes('charset='))) || 'charset=utf8'; // utf-8 is assumed when not specified;
299
- if (mediaType === 'application/json' && charset === 'charset=utf8') {
300
- acceptedMediaType = 'application/json';
299
+ if (mediaType === 'application/graphql-response+json' &&
300
+ charset === 'charset=utf8') {
301
+ acceptedMediaType = 'application/graphql-response+json';
301
302
  break;
302
303
  }
303
- if ((mediaType === 'application/graphql-response+json' ||
304
+ if ((mediaType === 'application/json' ||
304
305
  mediaType === 'application/*' ||
305
306
  mediaType === '*/*') &&
306
307
  charset === 'charset=utf8') {
307
- acceptedMediaType = 'application/graphql-response+json';
308
+ acceptedMediaType = 'application/json';
308
309
  break;
309
310
  }
310
311
  }
package/lib/handler.mjs CHANGED
@@ -291,15 +291,16 @@ export function getAcceptableMediaType(acceptHeader) {
291
291
  // TODO: handle the weight parameter "q"
292
292
  const [mediaType, ...params] = accept.split(';');
293
293
  const charset = (params === null || params === void 0 ? void 0 : params.find((param) => param.includes('charset='))) || 'charset=utf8'; // utf-8 is assumed when not specified;
294
- if (mediaType === 'application/json' && charset === 'charset=utf8') {
295
- acceptedMediaType = 'application/json';
294
+ if (mediaType === 'application/graphql-response+json' &&
295
+ charset === 'charset=utf8') {
296
+ acceptedMediaType = 'application/graphql-response+json';
296
297
  break;
297
298
  }
298
- if ((mediaType === 'application/graphql-response+json' ||
299
+ if ((mediaType === 'application/json' ||
299
300
  mediaType === 'application/*' ||
300
301
  mediaType === '*/*') &&
301
302
  charset === 'charset=utf8') {
302
- acceptedMediaType = 'application/graphql-response+json';
303
+ acceptedMediaType = 'application/json';
303
304
  break;
304
305
  }
305
306
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "graphql-http",
3
- "version": "1.7.1",
3
+ "version": "1.7.2",
4
4
  "description": "Simple, pluggable, zero-dependency, GraphQL over HTTP Protocol compliant server and client",
5
5
  "keywords": [
6
6
  "graphql",
Binary file