graphql-http 1.16.0 → 1.17.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.
package/README.md CHANGED
@@ -736,6 +736,36 @@ for (const audit of serverAudits({
736
736
 
737
737
  </details>
738
738
 
739
+ <details id="audit-deno">
740
+ <summary><a href="#audit-deno">🔗</a> Audit for servers usage in <a href="https://deno.land">Deno</a> environment</summary>
741
+
742
+ ```ts
743
+ import { serverAudits } from 'npm:graphql-http';
744
+
745
+ for (const audit of serverAudits({
746
+ url: 'http://localhost:4000/graphql',
747
+ fetchFn: fetch,
748
+ })) {
749
+ Deno.test(audit.name, async () => {
750
+ const result = await audit.fn();
751
+ if (result.status === 'error') {
752
+ throw result.reason;
753
+ }
754
+ if (result.status === 'warn') {
755
+ console.warn(result.reason); // or throw if you want full compliance (warnings are not requirements)
756
+ }
757
+ // Avoid leaking resources
758
+ if ('body' in result && result.body instanceof ReadableStream) {
759
+ await result.body.cancel();
760
+ }
761
+ });
762
+ }
763
+ ```
764
+
765
+ Put the above contents in a file and run it with `deno test --allow-net`.
766
+
767
+ </details>
768
+
739
769
  ## Only [GraphQL over HTTP](https://graphql.github.io/graphql-over-http/)
740
770
 
741
771
  This is the official [GraphQL over HTTP spec](https://graphql.github.io/graphql-over-http/) reference implementation and as such follows the specification strictly without any additional features (like file uploads, @stream/@defer directives and subscriptions).
@@ -744,7 +774,9 @@ Having said this, graphql-http is mostly aimed for library authors and simple se
744
774
 
745
775
  ## [Servers](/implementations)
746
776
 
747
- If you want a feature-full server with bleeding edge technologies, you're recommended to use one of the following.
777
+ If you want a feature-full server with bleeding edge technologies, you're recommended to use one of the following servers.
778
+
779
+ Their compliance with the [GraphQL over HTTP spec](https://graphql.github.io/graphql-over-http) is checked automatically and updated regularly.
748
780
 
749
781
  <!-- <ServersTable> -->
750
782
  <!-- prettier-ignore-start -->
@@ -768,16 +800,11 @@ Check the [docs folder](docs/) out for [TypeDoc](https://typedoc.org) generated
768
800
 
769
801
  ## [Audits](implementations/)
770
802
 
771
- Inspect audits of other implementations in the [implementations folder](implementations/). Adding your implementation is very welcome!
803
+ Inspect audits of other implementations in the [implementations folder](implementations).
804
+ Adding your implementation is very welcome, [see how](CONTRIBUTING.md#adding-implementations)!
772
805
 
773
806
  ## Want to help?
774
807
 
775
- File a bug, contribute with code, or improve documentation? Read up on our guidelines below and drive development with `yarn test --watch` away!
776
-
777
- This repository is managed by EasyCLA. Project participants must sign the free [GraphQL Specification Membership agreement](https://preview-spec-membership.graphql.org) before making a contribution. You only need to do this one time, and it can be signed by [individual contributors](http://individual-spec-membership.graphql.org/) or their [employers](http://corporate-spec-membership.graphql.org/).
778
-
779
- To initiate the signature process please open a PR against this repo. The EasyCLA bot will block the merge if we still need a membership agreement from you.
780
-
781
- You can find [detailed information here](https://github.com/graphql/graphql-wg/tree/main/membership). If you have issues, please email [operations@graphql.org](mailto:operations@graphql.org).
808
+ File a bug, contribute with code, or improve documentation? [Read more in CONTRIBUTING.md](CONTRIBUTING.md).
782
809
 
783
810
  If your company benefits from GraphQL and you would like to provide essential financial support for the systems and people that power our community, please also consider membership in the [GraphQL Foundation](https://foundation.graphql.org/join).
@@ -1,11 +1,19 @@
1
- import type { Request, Handler } from 'express';
1
+ import type { Request, Response, Handler } from 'express';
2
2
  import { HandlerOptions as RawHandlerOptions, OperationContext } from '../handler';
3
+ /**
4
+ * The context in the request for the handler.
5
+ *
6
+ * @category Server/express
7
+ */
8
+ export interface RequestContext {
9
+ res: Response;
10
+ }
3
11
  /**
4
12
  * Handler options when using the express adapter.
5
13
  *
6
14
  * @category Server/express
7
15
  */
8
- export type HandlerOptions<Context extends OperationContext = undefined> = RawHandlerOptions<Request, undefined, Context>;
16
+ export type HandlerOptions<Context extends OperationContext = undefined> = RawHandlerOptions<Request, RequestContext, Context>;
9
17
  /**
10
18
  * Create a GraphQL over HTTP spec compliant request handler for
11
19
  * the express framework.
@@ -1,11 +1,19 @@
1
- import type { Request, Handler } from 'express';
1
+ import type { Request, Response, Handler } from 'express';
2
2
  import { HandlerOptions as RawHandlerOptions, OperationContext } from '../handler';
3
+ /**
4
+ * The context in the request for the handler.
5
+ *
6
+ * @category Server/express
7
+ */
8
+ export interface RequestContext {
9
+ res: Response;
10
+ }
3
11
  /**
4
12
  * Handler options when using the express adapter.
5
13
  *
6
14
  * @category Server/express
7
15
  */
8
- export type HandlerOptions<Context extends OperationContext = undefined> = RawHandlerOptions<Request, undefined, Context>;
16
+ export type HandlerOptions<Context extends OperationContext = undefined> = RawHandlerOptions<Request, RequestContext, Context>;
9
17
  /**
10
18
  * Create a GraphQL over HTTP spec compliant request handler for
11
19
  * the express framework.
@@ -41,7 +41,7 @@ function createHandler(options) {
41
41
  });
42
42
  },
43
43
  raw: req,
44
- context: undefined,
44
+ context: { res },
45
45
  });
46
46
  res.writeHead(init.status, init.statusText, init.headers).end(body);
47
47
  }
@@ -38,7 +38,7 @@ export function createHandler(options) {
38
38
  });
39
39
  },
40
40
  raw: req,
41
- context: undefined,
41
+ context: { res },
42
42
  });
43
43
  res.writeHead(init.status, init.statusText, init.headers).end(body);
44
44
  }
@@ -1,11 +1,19 @@
1
- import type { FastifyRequest, RouteHandler } from 'fastify';
1
+ import type { FastifyRequest, FastifyReply, RouteHandler } from 'fastify';
2
2
  import { HandlerOptions as RawHandlerOptions, OperationContext } from '../handler';
3
+ /**
4
+ * The context in the request for the handler.
5
+ *
6
+ * @category Server/fastify
7
+ */
8
+ export interface RequestContext {
9
+ reply: FastifyReply;
10
+ }
3
11
  /**
4
12
  * Handler options when using the fastify adapter.
5
13
  *
6
14
  * @category Server/fastify
7
15
  */
8
- export type HandlerOptions<Context extends OperationContext = undefined> = RawHandlerOptions<FastifyRequest, undefined, Context>;
16
+ export type HandlerOptions<Context extends OperationContext = undefined> = RawHandlerOptions<FastifyRequest, RequestContext, Context>;
9
17
  /**
10
18
  * Create a GraphQL over HTTP spec compliant request handler for
11
19
  * the fastify framework.
@@ -1,11 +1,19 @@
1
- import type { FastifyRequest, RouteHandler } from 'fastify';
1
+ import type { FastifyRequest, FastifyReply, RouteHandler } from 'fastify';
2
2
  import { HandlerOptions as RawHandlerOptions, OperationContext } from '../handler';
3
+ /**
4
+ * The context in the request for the handler.
5
+ *
6
+ * @category Server/fastify
7
+ */
8
+ export interface RequestContext {
9
+ reply: FastifyReply;
10
+ }
3
11
  /**
4
12
  * Handler options when using the fastify adapter.
5
13
  *
6
14
  * @category Server/fastify
7
15
  */
8
- export type HandlerOptions<Context extends OperationContext = undefined> = RawHandlerOptions<FastifyRequest, undefined, Context>;
16
+ export type HandlerOptions<Context extends OperationContext = undefined> = RawHandlerOptions<FastifyRequest, RequestContext, Context>;
9
17
  /**
10
18
  * Create a GraphQL over HTTP spec compliant request handler for
11
19
  * the fastify framework.
@@ -32,7 +32,7 @@ function createHandler(options) {
32
32
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
33
33
  body: req.body,
34
34
  raw: req,
35
- context: undefined,
35
+ context: { reply },
36
36
  });
37
37
  reply
38
38
  .status(init.status)
@@ -29,7 +29,7 @@ export function createHandler(options) {
29
29
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
30
30
  body: req.body,
31
31
  raw: req,
32
- context: undefined,
32
+ context: { reply },
33
33
  });
34
34
  reply
35
35
  .status(init.status)
@@ -1,12 +1,20 @@
1
1
  /// <reference types="node" />
2
2
  import type { IncomingMessage, ServerResponse } from 'http';
3
3
  import { HandlerOptions as RawHandlerOptions, OperationContext } from '../handler';
4
+ /**
5
+ * The context in the request for the handler.
6
+ *
7
+ * @category Server/http
8
+ */
9
+ export interface RequestContext {
10
+ res: ServerResponse;
11
+ }
4
12
  /**
5
13
  * Handler options when using the http adapter.
6
14
  *
7
15
  * @category Server/http
8
16
  */
9
- export type HandlerOptions<Context extends OperationContext = undefined> = RawHandlerOptions<IncomingMessage, undefined, Context>;
17
+ export type HandlerOptions<Context extends OperationContext = undefined> = RawHandlerOptions<IncomingMessage, RequestContext, Context>;
10
18
  /**
11
19
  * Create a GraphQL over HTTP spec compliant request handler for
12
20
  * the Node environment http module.
package/lib/use/http.d.ts CHANGED
@@ -1,12 +1,20 @@
1
1
  /// <reference types="node" />
2
2
  import type { IncomingMessage, ServerResponse } from 'http';
3
3
  import { HandlerOptions as RawHandlerOptions, OperationContext } from '../handler';
4
+ /**
5
+ * The context in the request for the handler.
6
+ *
7
+ * @category Server/http
8
+ */
9
+ export interface RequestContext {
10
+ res: ServerResponse;
11
+ }
4
12
  /**
5
13
  * Handler options when using the http adapter.
6
14
  *
7
15
  * @category Server/http
8
16
  */
9
- export type HandlerOptions<Context extends OperationContext = undefined> = RawHandlerOptions<IncomingMessage, undefined, Context>;
17
+ export type HandlerOptions<Context extends OperationContext = undefined> = RawHandlerOptions<IncomingMessage, RequestContext, Context>;
10
18
  /**
11
19
  * Create a GraphQL over HTTP spec compliant request handler for
12
20
  * the Node environment http module.
package/lib/use/http.js CHANGED
@@ -40,7 +40,7 @@ function createHandler(options) {
40
40
  req.on('end', () => resolve(body));
41
41
  }),
42
42
  raw: req,
43
- context: undefined,
43
+ context: { res },
44
44
  });
45
45
  res.writeHead(init.status, init.statusText, init.headers).end(body);
46
46
  }
package/lib/use/http.mjs CHANGED
@@ -37,7 +37,7 @@ export function createHandler(options) {
37
37
  req.on('end', () => resolve(body));
38
38
  }),
39
39
  raw: req,
40
- context: undefined,
40
+ context: { res },
41
41
  });
42
42
  res.writeHead(init.status, init.statusText, init.headers).end(body);
43
43
  }
@@ -1,12 +1,20 @@
1
1
  /// <reference types="node" />
2
2
  import type { Http2ServerRequest, Http2ServerResponse } from 'http2';
3
3
  import { HandlerOptions as RawHandlerOptions, OperationContext } from '../handler';
4
+ /**
5
+ * The context in the request for the handler.
6
+ *
7
+ * @category Server/http2
8
+ */
9
+ export interface RequestContext {
10
+ res: Http2ServerResponse;
11
+ }
4
12
  /**
5
13
  * Handler options when using the http adapter.
6
14
  *
7
15
  * @category Server/http2
8
16
  */
9
- export type HandlerOptions<Context extends OperationContext = undefined> = RawHandlerOptions<Http2ServerRequest, undefined, Context>;
17
+ export type HandlerOptions<Context extends OperationContext = undefined> = RawHandlerOptions<Http2ServerRequest, RequestContext, Context>;
10
18
  /**
11
19
  * Create a GraphQL over HTTP spec compliant request handler for
12
20
  * the Node environment http2 module.
@@ -1,12 +1,20 @@
1
1
  /// <reference types="node" />
2
2
  import type { Http2ServerRequest, Http2ServerResponse } from 'http2';
3
3
  import { HandlerOptions as RawHandlerOptions, OperationContext } from '../handler';
4
+ /**
5
+ * The context in the request for the handler.
6
+ *
7
+ * @category Server/http2
8
+ */
9
+ export interface RequestContext {
10
+ res: Http2ServerResponse;
11
+ }
4
12
  /**
5
13
  * Handler options when using the http adapter.
6
14
  *
7
15
  * @category Server/http2
8
16
  */
9
- export type HandlerOptions<Context extends OperationContext = undefined> = RawHandlerOptions<Http2ServerRequest, undefined, Context>;
17
+ export type HandlerOptions<Context extends OperationContext = undefined> = RawHandlerOptions<Http2ServerRequest, RequestContext, Context>;
10
18
  /**
11
19
  * Create a GraphQL over HTTP spec compliant request handler for
12
20
  * the Node environment http2 module.
package/lib/use/http2.js CHANGED
@@ -52,7 +52,7 @@ function createHandler(options) {
52
52
  req.on('end', () => resolve(body));
53
53
  }),
54
54
  raw: req,
55
- context: undefined,
55
+ context: { res },
56
56
  });
57
57
  res.writeHead(init.status, init.statusText, init.headers);
58
58
  if (body) {
package/lib/use/http2.mjs CHANGED
@@ -49,7 +49,7 @@ export function createHandler(options) {
49
49
  req.on('end', () => resolve(body));
50
50
  }),
51
51
  raw: req,
52
- context: undefined,
52
+ context: { res },
53
53
  });
54
54
  res.writeHead(init.status, init.statusText, init.headers);
55
55
  if (body) {
package/lib/use/koa.d.mts CHANGED
@@ -1,13 +1,21 @@
1
1
  /// <reference types="node" />
2
- import type { Middleware } from 'koa';
2
+ import type { Middleware, Response } from 'koa';
3
3
  import type { IncomingMessage } from 'http';
4
4
  import { HandlerOptions as RawHandlerOptions, OperationContext } from '../handler';
5
+ /**
6
+ * The context in the request for the handler.
7
+ *
8
+ * @category Server/koa
9
+ */
10
+ export interface RequestContext {
11
+ res: Response;
12
+ }
5
13
  /**
6
14
  * Handler options when using the koa adapter.
7
15
  *
8
16
  * @category Server/koa
9
17
  */
10
- export type HandlerOptions<Context extends OperationContext = undefined> = RawHandlerOptions<IncomingMessage, undefined, Context>;
18
+ export type HandlerOptions<Context extends OperationContext = undefined> = RawHandlerOptions<IncomingMessage, RequestContext, Context>;
11
19
  /**
12
20
  * Create a GraphQL over HTTP spec compliant request handler for
13
21
  * the Koa framework.
package/lib/use/koa.d.ts CHANGED
@@ -1,13 +1,21 @@
1
1
  /// <reference types="node" />
2
- import type { Middleware } from 'koa';
2
+ import type { Middleware, Response } from 'koa';
3
3
  import type { IncomingMessage } from 'http';
4
4
  import { HandlerOptions as RawHandlerOptions, OperationContext } from '../handler';
5
+ /**
6
+ * The context in the request for the handler.
7
+ *
8
+ * @category Server/koa
9
+ */
10
+ export interface RequestContext {
11
+ res: Response;
12
+ }
5
13
  /**
6
14
  * Handler options when using the koa adapter.
7
15
  *
8
16
  * @category Server/koa
9
17
  */
10
- export type HandlerOptions<Context extends OperationContext = undefined> = RawHandlerOptions<IncomingMessage, undefined, Context>;
18
+ export type HandlerOptions<Context extends OperationContext = undefined> = RawHandlerOptions<IncomingMessage, RequestContext, Context>;
11
19
  /**
12
20
  * Create a GraphQL over HTTP spec compliant request handler for
13
21
  * the Koa framework.
package/lib/use/koa.js CHANGED
@@ -42,7 +42,7 @@ function createHandler(options) {
42
42
  });
43
43
  },
44
44
  raw: ctx.req,
45
- context: undefined,
45
+ context: { res: ctx.response },
46
46
  });
47
47
  ctx.body = body;
48
48
  ctx.response.status = init.status;
package/lib/use/koa.mjs CHANGED
@@ -39,7 +39,7 @@ export function createHandler(options) {
39
39
  });
40
40
  },
41
41
  raw: ctx.req,
42
- context: undefined,
42
+ context: { res: ctx.response },
43
43
  });
44
44
  ctx.body = body;
45
45
  ctx.response.status = init.status;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "graphql-http",
3
- "version": "1.16.0",
3
+ "version": "1.17.0",
4
4
  "description": "Simple, pluggable, zero-dependency, GraphQL over HTTP spec compliant server, client and audit suite.",
5
5
  "keywords": [
6
6
  "graphql",
@@ -24,7 +24,7 @@
24
24
  "engines": {
25
25
  "node": ">=12"
26
26
  },
27
- "packageManager": "yarn@3.4.1",
27
+ "packageManager": "yarn@3.5.0",
28
28
  "main": "lib/index.js",
29
29
  "module": "lib/index.mjs",
30
30
  "browser": "umd/graphql-http.js",
@@ -88,7 +88,8 @@
88
88
  "scripts": {
89
89
  "gendocs": "typedoc --options typedoc.js src/",
90
90
  "lint:eslint": "eslint 'src'",
91
- "lint:prettier": "prettier -c .",
91
+ "lint:prettier": "prettier --check .",
92
+ "lint:fix": "yarn lint:eslint --fix && yarn lint:prettier --write",
92
93
  "lint": "yarn lint:eslint && yarn lint:prettier",
93
94
  "type-check": "tsc --noEmit",
94
95
  "test": "NODE_OPTIONS=--experimental-vm-modules NODE_NO_WARNINGS=1 jest",
@@ -105,47 +106,47 @@
105
106
  "graphql": ">=0.11 <=16"
106
107
  },
107
108
  "devDependencies": {
108
- "@babel/core": "^7.20.12",
109
+ "@babel/core": "^7.21.3",
109
110
  "@babel/plugin-proposal-class-properties": "^7.18.6",
110
111
  "@babel/plugin-proposal-nullish-coalescing-operator": "^7.18.6",
111
112
  "@babel/plugin-proposal-object-rest-spread": "^7.20.7",
112
- "@babel/plugin-proposal-optional-chaining": "^7.20.7",
113
+ "@babel/plugin-proposal-optional-chaining": "^7.21.0",
113
114
  "@babel/preset-env": "^7.20.2",
114
- "@babel/preset-typescript": "^7.18.6",
115
+ "@babel/preset-typescript": "^7.21.0",
115
116
  "@rollup/plugin-terser": "^0.4.0",
116
117
  "@rollup/plugin-typescript": "^11.0.0",
117
- "@semantic-release/changelog": "^6.0.2",
118
+ "@semantic-release/changelog": "^6.0.3",
118
119
  "@semantic-release/git": "^10.0.1",
119
- "@types/eslint": "^8.21.0",
120
+ "@types/eslint": "^8.21.3",
120
121
  "@types/express": "^4.17.17",
121
- "@types/glob": "^8.0.1",
122
+ "@types/glob": "^8.1.0",
122
123
  "@types/html-validator": "^5.0.3",
123
- "@types/jest": "^29.4.0",
124
- "@types/koa": "^2.13.5",
124
+ "@types/jest": "^29.5.0",
125
+ "@types/koa": "^2.13.6",
125
126
  "@types/koa-mount": "^4.0.2",
126
- "@typescript-eslint/eslint-plugin": "^5.51.0",
127
- "@typescript-eslint/parser": "^5.51.0",
128
- "@whatwg-node/fetch": "^0.8.1",
129
- "babel-jest": "^29.4.2",
130
- "eslint": "^8.34.0",
131
- "eslint-config-prettier": "^8.6.0",
127
+ "@typescript-eslint/eslint-plugin": "^5.57.0",
128
+ "@typescript-eslint/parser": "^5.57.0",
129
+ "@whatwg-node/fetch": "^0.8.4",
130
+ "babel-jest": "^29.5.0",
131
+ "eslint": "^8.36.0",
132
+ "eslint-config-prettier": "^8.8.0",
132
133
  "express": "^4.18.2",
133
- "fastify": "^4.13.0",
134
+ "fastify": "^4.15.0",
134
135
  "graphql": "^16.6.0",
135
136
  "html-validator": "^6.0.1",
136
- "jest": "^29.4.2",
137
- "jest-jasmine2": "^29.4.2",
137
+ "jest": "^29.5.0",
138
+ "jest-jasmine2": "^29.5.0",
138
139
  "koa": "^2.14.1",
139
140
  "koa-mount": "^4.0.0",
140
- "node-fetch": "^3.3.0",
141
- "prettier": "^2.8.4",
142
- "rollup": "^3.15.0",
141
+ "node-fetch": "^3.3.1",
142
+ "prettier": "^2.8.7",
143
+ "rollup": "^3.20.2",
143
144
  "rollup-plugin-gzip": "^3.1.0",
144
- "semantic-release": "^20.1.0",
145
+ "semantic-release": "^21.0.0",
145
146
  "tslib": "^2.5.0",
146
- "typedoc": "^0.23.25",
147
+ "typedoc": "^0.23.28",
147
148
  "typedoc-plugin-markdown": "^3.14.0",
148
- "typescript": "^4.9.5"
149
+ "typescript": "^5.0.2"
149
150
  },
150
151
  "resolutions": {
151
152
  "npm/libnpmversion": "^3.0.6"