graphql-http 1.9.0 → 1.10.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.
@@ -8,13 +8,13 @@
8
8
  *
9
9
  * @category Audits
10
10
  */
11
- export declare type AuditRequirement = 'MUST' | 'SHOULD' | 'MAY';
11
+ export type AuditRequirement = 'MUST' | 'SHOULD' | 'MAY';
12
12
  /**
13
13
  * Audit name starting with the audit requirement level.
14
14
  *
15
15
  * @category Audits
16
16
  */
17
- export declare type AuditName = `${AuditRequirement} ${string}`;
17
+ export type AuditName = `${AuditRequirement} ${string}`;
18
18
  /**
19
19
  * Actual audit test returning an result.
20
20
  *
@@ -55,4 +55,4 @@ export interface AuditFail {
55
55
  *
56
56
  * @category Audits
57
57
  */
58
- export declare type AuditResult = AuditOk | AuditFail;
58
+ export type AuditResult = AuditOk | AuditFail;
@@ -8,13 +8,13 @@
8
8
  *
9
9
  * @category Audits
10
10
  */
11
- export declare type AuditRequirement = 'MUST' | 'SHOULD' | 'MAY';
11
+ export type AuditRequirement = 'MUST' | 'SHOULD' | 'MAY';
12
12
  /**
13
13
  * Audit name starting with the audit requirement level.
14
14
  *
15
15
  * @category Audits
16
16
  */
17
- export declare type AuditName = `${AuditRequirement} ${string}`;
17
+ export type AuditName = `${AuditRequirement} ${string}`;
18
18
  /**
19
19
  * Actual audit test returning an result.
20
20
  *
@@ -55,4 +55,4 @@ export interface AuditFail {
55
55
  *
56
56
  * @category Audits
57
57
  */
58
- export declare type AuditResult = AuditOk | AuditFail;
58
+ export type AuditResult = AuditOk | AuditFail;
package/lib/handler.d.mts CHANGED
@@ -10,7 +10,7 @@ import { RequestParams } from './common';
10
10
  *
11
11
  * @category Server
12
12
  */
13
- export declare type RequestHeaders = {
13
+ export type RequestHeaders = {
14
14
  /**
15
15
  * Always an array in Node. Duplicates are added to it.
16
16
  * Not necessarily true for other environments.
@@ -54,7 +54,7 @@ export interface Request<Raw, Context> {
54
54
  *
55
55
  * @category Server
56
56
  */
57
- export declare type ResponseHeaders = {
57
+ export type ResponseHeaders = {
58
58
  accept?: string;
59
59
  allow?: string;
60
60
  'content-type'?: string;
@@ -65,7 +65,7 @@ export declare type ResponseHeaders = {
65
65
  *
66
66
  * @category Server
67
67
  */
68
- export declare type ResponseBody = string;
68
+ export type ResponseBody = string;
69
69
  /**
70
70
  * Server agnostic response options (ex. status and headers) returned from
71
71
  * `graphql-http` needing to be coerced to the server implementation in use.
@@ -83,7 +83,7 @@ export interface ResponseInit {
83
83
  *
84
84
  * @category Server
85
85
  */
86
- export declare type Response = readonly [body: ResponseBody | null, init: ResponseInit];
86
+ export type Response = readonly [body: ResponseBody | null, init: ResponseInit];
87
87
  /**
88
88
  * Checks whether the passed value is the `graphql-http` server agnostic response.
89
89
  *
@@ -100,9 +100,9 @@ export declare function isResponse(val: unknown): val is Response;
100
100
  *
101
101
  * @category Server
102
102
  */
103
- export declare type OperationContext = Record<PropertyKey, unknown> | symbol | number | string | boolean | undefined | null;
103
+ export type OperationContext = Record<PropertyKey, unknown> | symbol | number | string | boolean | undefined | null;
104
104
  /** @category Server */
105
- export declare type OperationArgs<Context extends OperationContext = undefined> = ExecutionArgs & {
105
+ export type OperationArgs<Context extends OperationContext = undefined> = ExecutionArgs & {
106
106
  contextValue?: Context;
107
107
  };
108
108
  /** @category Server */
@@ -150,6 +150,15 @@ export interface HandlerOptions<RequestRaw = unknown, RequestContext = unknown,
150
150
  * GraphQL operation AST getter used for detecting the operation type.
151
151
  */
152
152
  getOperationAST?: typeof graphqlGetOperationAST;
153
+ /**
154
+ * The GraphQL root value or resolvers to go alongside the execution.
155
+ * Learn more about them here: https://graphql.org/learn/execution/#root-fields-resolvers.
156
+ *
157
+ * If you return from `onSubscribe`, and the returned value is
158
+ * missing the `rootValue` field, the relevant operation root
159
+ * will be used instead.
160
+ */
161
+ rootValue?: unknown;
153
162
  /**
154
163
  * The subscribe callback executed right after processing the request
155
164
  * before proceeding with the GraphQL operation execution.
@@ -204,7 +213,7 @@ export interface HandlerOptions<RequestRaw = unknown, RequestContext = unknown,
204
213
  *
205
214
  * @category Server
206
215
  */
207
- export declare type Handler<RequestRaw = unknown, RequestContext = unknown> = (req: Request<RequestRaw, RequestContext>) => Promise<Response>;
216
+ export type Handler<RequestRaw = unknown, RequestContext = unknown> = (req: Request<RequestRaw, RequestContext>) => Promise<Response>;
208
217
  /**
209
218
  * Makes a GraphQL over HTTP Protocol compliant server handler. The handler can
210
219
  * be used with your favourite server library.
@@ -266,7 +275,7 @@ export declare function createHandler<RequestRaw = unknown, RequestContext = unk
266
275
  *
267
276
  * @category Server
268
277
  */
269
- export declare type AcceptableMediaType = 'application/graphql-response+json' | 'application/json';
278
+ export type AcceptableMediaType = 'application/graphql-response+json' | 'application/json';
270
279
  /**
271
280
  * Inspects the request and detects the appropriate/acceptable Media-Type
272
281
  * looking at the `Accept` header while complying with the GraphQL over HTTP Protocol.
package/lib/handler.d.ts CHANGED
@@ -10,7 +10,7 @@ import { RequestParams } from './common';
10
10
  *
11
11
  * @category Server
12
12
  */
13
- export declare type RequestHeaders = {
13
+ export type RequestHeaders = {
14
14
  /**
15
15
  * Always an array in Node. Duplicates are added to it.
16
16
  * Not necessarily true for other environments.
@@ -54,7 +54,7 @@ export interface Request<Raw, Context> {
54
54
  *
55
55
  * @category Server
56
56
  */
57
- export declare type ResponseHeaders = {
57
+ export type ResponseHeaders = {
58
58
  accept?: string;
59
59
  allow?: string;
60
60
  'content-type'?: string;
@@ -65,7 +65,7 @@ export declare type ResponseHeaders = {
65
65
  *
66
66
  * @category Server
67
67
  */
68
- export declare type ResponseBody = string;
68
+ export type ResponseBody = string;
69
69
  /**
70
70
  * Server agnostic response options (ex. status and headers) returned from
71
71
  * `graphql-http` needing to be coerced to the server implementation in use.
@@ -83,7 +83,7 @@ export interface ResponseInit {
83
83
  *
84
84
  * @category Server
85
85
  */
86
- export declare type Response = readonly [body: ResponseBody | null, init: ResponseInit];
86
+ export type Response = readonly [body: ResponseBody | null, init: ResponseInit];
87
87
  /**
88
88
  * Checks whether the passed value is the `graphql-http` server agnostic response.
89
89
  *
@@ -100,9 +100,9 @@ export declare function isResponse(val: unknown): val is Response;
100
100
  *
101
101
  * @category Server
102
102
  */
103
- export declare type OperationContext = Record<PropertyKey, unknown> | symbol | number | string | boolean | undefined | null;
103
+ export type OperationContext = Record<PropertyKey, unknown> | symbol | number | string | boolean | undefined | null;
104
104
  /** @category Server */
105
- export declare type OperationArgs<Context extends OperationContext = undefined> = ExecutionArgs & {
105
+ export type OperationArgs<Context extends OperationContext = undefined> = ExecutionArgs & {
106
106
  contextValue?: Context;
107
107
  };
108
108
  /** @category Server */
@@ -150,6 +150,15 @@ export interface HandlerOptions<RequestRaw = unknown, RequestContext = unknown,
150
150
  * GraphQL operation AST getter used for detecting the operation type.
151
151
  */
152
152
  getOperationAST?: typeof graphqlGetOperationAST;
153
+ /**
154
+ * The GraphQL root value or resolvers to go alongside the execution.
155
+ * Learn more about them here: https://graphql.org/learn/execution/#root-fields-resolvers.
156
+ *
157
+ * If you return from `onSubscribe`, and the returned value is
158
+ * missing the `rootValue` field, the relevant operation root
159
+ * will be used instead.
160
+ */
161
+ rootValue?: unknown;
153
162
  /**
154
163
  * The subscribe callback executed right after processing the request
155
164
  * before proceeding with the GraphQL operation execution.
@@ -204,7 +213,7 @@ export interface HandlerOptions<RequestRaw = unknown, RequestContext = unknown,
204
213
  *
205
214
  * @category Server
206
215
  */
207
- export declare type Handler<RequestRaw = unknown, RequestContext = unknown> = (req: Request<RequestRaw, RequestContext>) => Promise<Response>;
216
+ export type Handler<RequestRaw = unknown, RequestContext = unknown> = (req: Request<RequestRaw, RequestContext>) => Promise<Response>;
208
217
  /**
209
218
  * Makes a GraphQL over HTTP Protocol compliant server handler. The handler can
210
219
  * be used with your favourite server library.
@@ -266,7 +275,7 @@ export declare function createHandler<RequestRaw = unknown, RequestContext = unk
266
275
  *
267
276
  * @category Server
268
277
  */
269
- export declare type AcceptableMediaType = 'application/graphql-response+json' | 'application/json';
278
+ export type AcceptableMediaType = 'application/graphql-response+json' | 'application/json';
270
279
  /**
271
280
  * Inspects the request and detects the appropriate/acceptable Media-Type
272
281
  * looking at the `Accept` header while complying with the GraphQL over HTTP Protocol.
package/lib/handler.js CHANGED
@@ -76,7 +76,7 @@ exports.isResponse = isResponse;
76
76
  * @category Server
77
77
  */
78
78
  function createHandler(options) {
79
- const { schema, context, validate = graphql_1.validate, execute = graphql_1.execute, parse = graphql_1.parse, getOperationAST = graphql_1.getOperationAST, onSubscribe, onOperation, } = options;
79
+ const { schema, context, validate = graphql_1.validate, execute = graphql_1.execute, parse = graphql_1.parse, getOperationAST = graphql_1.getOperationAST, rootValue, onSubscribe, onOperation, } = options;
80
80
  return async function handler(req) {
81
81
  var _a, _b;
82
82
  const method = req.method;
@@ -260,6 +260,9 @@ function createHandler(options) {
260
260
  },
261
261
  ];
262
262
  }
263
+ if (!('rootValue' in args)) {
264
+ args.rootValue = rootValue;
265
+ }
263
266
  if (!('contextValue' in args)) {
264
267
  const resOrContext = typeof context === 'function' ? await context(req, params) : context;
265
268
  if (isResponse(resOrContext))
package/lib/handler.mjs CHANGED
@@ -72,7 +72,7 @@ export function isResponse(val) {
72
72
  * @category Server
73
73
  */
74
74
  export function createHandler(options) {
75
- const { schema, context, validate = graphqlValidate, execute = graphqlExecute, parse = graphqlParse, getOperationAST = graphqlGetOperationAST, onSubscribe, onOperation, } = options;
75
+ const { schema, context, validate = graphqlValidate, execute = graphqlExecute, parse = graphqlParse, getOperationAST = graphqlGetOperationAST, rootValue, onSubscribe, onOperation, } = options;
76
76
  return async function handler(req) {
77
77
  var _a, _b;
78
78
  const method = req.method;
@@ -256,6 +256,9 @@ export function createHandler(options) {
256
256
  },
257
257
  ];
258
258
  }
259
+ if (!('rootValue' in args)) {
260
+ args.rootValue = rootValue;
261
+ }
259
262
  if (!('contextValue' in args)) {
260
263
  const resOrContext = typeof context === 'function' ? await context(req, params) : context;
261
264
  if (isResponse(resOrContext))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "graphql-http",
3
- "version": "1.9.0",
3
+ "version": "1.10.0",
4
4
  "description": "Simple, pluggable, zero-dependency, GraphQL over HTTP Protocol compliant server and client",
5
5
  "keywords": [
6
6
  "graphql",
@@ -24,7 +24,7 @@
24
24
  "engines": {
25
25
  "node": ">=12"
26
26
  },
27
- "packageManager": "yarn@3.2.4",
27
+ "packageManager": "yarn@3.3.1",
28
28
  "main": "lib/index.js",
29
29
  "module": "lib/index.mjs",
30
30
  "browser": "umd/graphql-http.js",
@@ -72,12 +72,14 @@
72
72
  },
73
73
  "scripts": {
74
74
  "gendocs": "typedoc --options typedoc.js src/",
75
- "lint": "eslint 'src'",
75
+ "lint:eslint": "eslint 'src'",
76
+ "lint:prettier": "prettier -c .",
77
+ "lint": "yarn lint:eslint && yarn lint:prettier",
76
78
  "type-check": "tsc --noEmit",
77
79
  "test": "NODE_OPTIONS=--experimental-vm-modules jest",
78
80
  "build:esm": "tsc -b tsconfig.esm.json && node scripts/esm-post-process.mjs",
79
81
  "build:cjs": "tsc -b tsconfig.cjs.json",
80
- "build:umd": "rollup -c && gzip umd/graphql-http.min.js -c > umd/graphql-http.min.js.gz",
82
+ "build:umd": "rollup --bundleConfigAsCjs --config rollup.config.ts --configPlugin typescript && gzip umd/graphql-http.min.js -c > umd/graphql-http.min.js.gz",
81
83
  "build": "yarn build:esm && yarn build:cjs && yarn build:umd",
82
84
  "release": "semantic-release"
83
85
  },
@@ -88,39 +90,40 @@
88
90
  "graphql": ">=0.11 <=16"
89
91
  },
90
92
  "devDependencies": {
91
- "@babel/core": "^7.20.2",
93
+ "@babel/core": "^7.20.7",
92
94
  "@babel/plugin-proposal-class-properties": "^7.18.6",
93
95
  "@babel/plugin-proposal-nullish-coalescing-operator": "^7.18.6",
94
- "@babel/plugin-proposal-object-rest-spread": "^7.20.2",
95
- "@babel/plugin-proposal-optional-chaining": "^7.18.9",
96
+ "@babel/plugin-proposal-object-rest-spread": "^7.20.7",
97
+ "@babel/plugin-proposal-optional-chaining": "^7.20.7",
96
98
  "@babel/preset-env": "^7.20.2",
97
99
  "@babel/preset-typescript": "^7.18.6",
98
- "@rollup/plugin-typescript": "^9.0.2",
99
- "@semantic-release/changelog": "^6.0.1",
100
+ "@rollup/plugin-terser": "^0.2.1",
101
+ "@rollup/plugin-typescript": "^10.0.1",
102
+ "@semantic-release/changelog": "^6.0.2",
100
103
  "@semantic-release/git": "^10.0.1",
101
- "@types/express": "^4.17.14",
102
- "@types/jest": "^29.2.2",
103
- "@typescript-eslint/eslint-plugin": "^5.42.1",
104
- "@typescript-eslint/parser": "^5.42.1",
105
- "@whatwg-node/fetch": "^0.5.1",
106
- "babel-jest": "^29.3.0",
107
- "eslint": "^8.27.0",
104
+ "@types/eslint": "^8.4.10",
105
+ "@types/express": "^4.17.15",
106
+ "@types/glob": "^8.0.0",
107
+ "@types/jest": "^29.2.4",
108
+ "@typescript-eslint/eslint-plugin": "^5.47.0",
109
+ "@typescript-eslint/parser": "^5.47.0",
110
+ "@whatwg-node/fetch": "^0.5.3",
111
+ "babel-jest": "^29.3.1",
112
+ "eslint": "^8.30.0",
108
113
  "eslint-config-prettier": "^8.5.0",
109
- "eslint-plugin-prettier": "^4.2.1",
110
114
  "express": "^4.18.2",
111
- "fastify": "^4.9.2",
115
+ "fastify": "^4.10.2",
112
116
  "graphql": "^16.6.0",
113
- "jest": "^29.3.0",
114
- "jest-jasmine2": "^29.3.0",
115
- "node-fetch": "^3.2.10",
116
- "prettier": "^2.7.1",
117
- "rollup": "^3.2.5",
118
- "rollup-plugin-terser": "^7.0.2",
117
+ "jest": "^29.3.1",
118
+ "jest-jasmine2": "^29.3.1",
119
+ "node-fetch": "^3.3.0",
120
+ "prettier": "^2.8.1",
121
+ "rollup": "^3.8.1",
119
122
  "semantic-release": "^19.0.5",
120
123
  "tslib": "^2.4.1",
121
- "typedoc": "^0.23.20",
122
- "typedoc-plugin-markdown": "^3.13.6",
123
- "typescript": "^4.8.4"
124
+ "typedoc": "^0.23.23",
125
+ "typedoc-plugin-markdown": "^3.14.0",
126
+ "typescript": "^4.9.4"
124
127
  },
125
128
  "resolutions": {
126
129
  "npm/libnpmversion": "^3.0.6"
Binary file