@depup/express-graphql 0.12.0-depup.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/LICENSE +21 -0
- package/README.md +34 -0
- package/changes.json +22 -0
- package/index.d.ts +146 -0
- package/index.js +285 -0
- package/package.json +76 -0
- package/parseBody.d.ts +13 -0
- package/parseBody.js +110 -0
- package/renderGraphiQL.d.ts +30 -0
- package/renderGraphiQL.js +171 -0
- package/ts3.4/index.d.ts +146 -0
- package/ts3.4/parseBody.d.ts +13 -0
- package/ts3.4/renderGraphiQL.d.ts +30 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) GraphQL Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# @depup/express-graphql
|
|
2
|
+
|
|
3
|
+
> Dependency-bumped version of [express-graphql](https://www.npmjs.com/package/express-graphql)
|
|
4
|
+
|
|
5
|
+
Generated by [DepUp](https://github.com/depup/npm) -- all production
|
|
6
|
+
dependencies bumped to latest versions.
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install @depup/express-graphql
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
| Field | Value |
|
|
15
|
+
|-------|-------|
|
|
16
|
+
| Original | [express-graphql](https://www.npmjs.com/package/express-graphql) @ 0.12.0 |
|
|
17
|
+
| Processed | 2026-03-19 |
|
|
18
|
+
| Smoke test | passed |
|
|
19
|
+
| Deps updated | 4 |
|
|
20
|
+
|
|
21
|
+
## Dependency Changes
|
|
22
|
+
|
|
23
|
+
| Dependency | From | To |
|
|
24
|
+
|------------|------|-----|
|
|
25
|
+
| accepts | ^1.3.7 | ^1.3.8 |
|
|
26
|
+
| content-type | ^1.0.4 | ^1.0.5 |
|
|
27
|
+
| http-errors | 1.8.0 | ^2.0.1 |
|
|
28
|
+
| raw-body | ^2.4.1 | ^3.0.2 |
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
Source: https://github.com/depup/npm | Original: https://www.npmjs.com/package/express-graphql
|
|
33
|
+
|
|
34
|
+
License inherited from the original package.
|
package/changes.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"bumped": {
|
|
3
|
+
"accepts": {
|
|
4
|
+
"from": "^1.3.7",
|
|
5
|
+
"to": "^1.3.8"
|
|
6
|
+
},
|
|
7
|
+
"content-type": {
|
|
8
|
+
"from": "^1.0.4",
|
|
9
|
+
"to": "^1.0.5"
|
|
10
|
+
},
|
|
11
|
+
"http-errors": {
|
|
12
|
+
"from": "1.8.0",
|
|
13
|
+
"to": "^2.0.1"
|
|
14
|
+
},
|
|
15
|
+
"raw-body": {
|
|
16
|
+
"from": "^2.4.1",
|
|
17
|
+
"to": "^3.0.2"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"timestamp": "2026-03-19T03:01:44.867Z",
|
|
21
|
+
"totalUpdated": 4
|
|
22
|
+
}
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { IncomingMessage, ServerResponse } from 'http';
|
|
3
|
+
import type { ASTVisitor, DocumentNode, ValidationRule, ValidationContext, ExecutionArgs, ExecutionResult, FormattedExecutionResult, GraphQLSchema, GraphQLFieldResolver, GraphQLTypeResolver, GraphQLFormattedError } from 'graphql';
|
|
4
|
+
import { Source, GraphQLError } from 'graphql';
|
|
5
|
+
import type { GraphiQLOptions } from './renderGraphiQL';
|
|
6
|
+
declare type Request = IncomingMessage & {
|
|
7
|
+
url: string;
|
|
8
|
+
};
|
|
9
|
+
declare type Response = ServerResponse & {
|
|
10
|
+
json?: (data: unknown) => void;
|
|
11
|
+
};
|
|
12
|
+
declare type MaybePromise<T> = Promise<T> | T;
|
|
13
|
+
/**
|
|
14
|
+
* Used to configure the graphqlHTTP middleware by providing a schema
|
|
15
|
+
* and other configuration options.
|
|
16
|
+
*
|
|
17
|
+
* Options can be provided as an Object, a Promise for an Object, or a Function
|
|
18
|
+
* that returns an Object or a Promise for an Object.
|
|
19
|
+
*/
|
|
20
|
+
export declare type Options = ((request: Request, response: Response, params?: GraphQLParams) => MaybePromise<OptionsData>) | MaybePromise<OptionsData>;
|
|
21
|
+
export interface OptionsData {
|
|
22
|
+
/**
|
|
23
|
+
* A GraphQL schema from graphql-js.
|
|
24
|
+
*/
|
|
25
|
+
schema: GraphQLSchema;
|
|
26
|
+
/**
|
|
27
|
+
* A value to pass as the context to this middleware.
|
|
28
|
+
*/
|
|
29
|
+
context?: unknown;
|
|
30
|
+
/**
|
|
31
|
+
* An object to pass as the rootValue to the graphql() function.
|
|
32
|
+
*/
|
|
33
|
+
rootValue?: unknown;
|
|
34
|
+
/**
|
|
35
|
+
* A boolean to configure whether the output should be pretty-printed.
|
|
36
|
+
*/
|
|
37
|
+
pretty?: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* An optional array of validation rules that will be applied on the document
|
|
40
|
+
* in additional to those defined by the GraphQL spec.
|
|
41
|
+
*/
|
|
42
|
+
validationRules?: ReadonlyArray<(ctx: ValidationContext) => ASTVisitor>;
|
|
43
|
+
/**
|
|
44
|
+
* An optional function which will be used to validate instead of default `validate`
|
|
45
|
+
* from `graphql-js`.
|
|
46
|
+
*/
|
|
47
|
+
customValidateFn?: (schema: GraphQLSchema, documentAST: DocumentNode, rules: ReadonlyArray<ValidationRule>) => ReadonlyArray<GraphQLError>;
|
|
48
|
+
/**
|
|
49
|
+
* An optional function which will be used to execute instead of default `execute`
|
|
50
|
+
* from `graphql-js`.
|
|
51
|
+
*/
|
|
52
|
+
customExecuteFn?: (args: ExecutionArgs) => MaybePromise<ExecutionResult>;
|
|
53
|
+
/**
|
|
54
|
+
* An optional function which will be used to format any errors produced by
|
|
55
|
+
* fulfilling a GraphQL operation. If no function is provided, GraphQL's
|
|
56
|
+
* default spec-compliant `formatError` function will be used.
|
|
57
|
+
*/
|
|
58
|
+
customFormatErrorFn?: (error: GraphQLError) => GraphQLFormattedError;
|
|
59
|
+
/**
|
|
60
|
+
* An optional function which will be used to create a document instead of
|
|
61
|
+
* the default `parse` from `graphql-js`.
|
|
62
|
+
*/
|
|
63
|
+
customParseFn?: (source: Source) => DocumentNode;
|
|
64
|
+
/**
|
|
65
|
+
* `formatError` is deprecated and replaced by `customFormatErrorFn`. It will
|
|
66
|
+
* be removed in version 1.0.0.
|
|
67
|
+
*/
|
|
68
|
+
formatError?: (error: GraphQLError) => GraphQLFormattedError;
|
|
69
|
+
/**
|
|
70
|
+
* An optional function for adding additional metadata to the GraphQL response
|
|
71
|
+
* as a key-value object. The result will be added to "extensions" field in
|
|
72
|
+
* the resulting JSON. This is often a useful place to add development time
|
|
73
|
+
* info such as the runtime of a query or the amount of resources consumed.
|
|
74
|
+
*
|
|
75
|
+
* Information about the request is provided to be used.
|
|
76
|
+
*
|
|
77
|
+
* This function may be async.
|
|
78
|
+
*/
|
|
79
|
+
extensions?: (info: RequestInfo) => MaybePromise<undefined | {
|
|
80
|
+
[key: string]: unknown;
|
|
81
|
+
}>;
|
|
82
|
+
/**
|
|
83
|
+
* A boolean to optionally enable GraphiQL mode.
|
|
84
|
+
* Alternatively, instead of `true` you can pass in an options object.
|
|
85
|
+
*/
|
|
86
|
+
graphiql?: boolean | GraphiQLOptions;
|
|
87
|
+
/**
|
|
88
|
+
* A resolver function to use when one is not provided by the schema.
|
|
89
|
+
* If not provided, the default field resolver is used (which looks for a
|
|
90
|
+
* value or method on the source value with the field's name).
|
|
91
|
+
*/
|
|
92
|
+
fieldResolver?: GraphQLFieldResolver<unknown, unknown>;
|
|
93
|
+
/**
|
|
94
|
+
* A type resolver function to use when none is provided by the schema.
|
|
95
|
+
* If not provided, the default type resolver is used (which looks for a
|
|
96
|
+
* `__typename` field or alternatively calls the `isTypeOf` method).
|
|
97
|
+
*/
|
|
98
|
+
typeResolver?: GraphQLTypeResolver<unknown, unknown>;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* All information about a GraphQL request.
|
|
102
|
+
*/
|
|
103
|
+
export interface RequestInfo {
|
|
104
|
+
/**
|
|
105
|
+
* The parsed GraphQL document.
|
|
106
|
+
*/
|
|
107
|
+
document: DocumentNode;
|
|
108
|
+
/**
|
|
109
|
+
* The variable values used at runtime.
|
|
110
|
+
*/
|
|
111
|
+
variables: {
|
|
112
|
+
readonly [name: string]: unknown;
|
|
113
|
+
} | null;
|
|
114
|
+
/**
|
|
115
|
+
* The (optional) operation name requested.
|
|
116
|
+
*/
|
|
117
|
+
operationName: string | null;
|
|
118
|
+
/**
|
|
119
|
+
* The result of executing the operation.
|
|
120
|
+
*/
|
|
121
|
+
result: FormattedExecutionResult;
|
|
122
|
+
/**
|
|
123
|
+
* A value to pass as the context to the graphql() function.
|
|
124
|
+
*/
|
|
125
|
+
context?: unknown;
|
|
126
|
+
}
|
|
127
|
+
declare type Middleware = (request: Request, response: Response) => Promise<void>;
|
|
128
|
+
/**
|
|
129
|
+
* Middleware for express; takes an options object or function as input to
|
|
130
|
+
* configure behavior, and returns an express middleware.
|
|
131
|
+
*/
|
|
132
|
+
export declare function graphqlHTTP(options: Options): Middleware;
|
|
133
|
+
export interface GraphQLParams {
|
|
134
|
+
query: string | null;
|
|
135
|
+
variables: {
|
|
136
|
+
readonly [name: string]: unknown;
|
|
137
|
+
} | null;
|
|
138
|
+
operationName: string | null;
|
|
139
|
+
raw: boolean;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Provided a "Request" provided by express or connect (typically a node style
|
|
143
|
+
* HTTPClientRequest), Promise the GraphQL request parameters.
|
|
144
|
+
*/
|
|
145
|
+
export declare function getGraphQLParams(request: Request): Promise<GraphQLParams>;
|
|
146
|
+
export {};
|
package/index.js
ADDED
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getGraphQLParams = exports.graphqlHTTP = void 0;
|
|
7
|
+
const accepts_1 = __importDefault(require("accepts"));
|
|
8
|
+
const http_errors_1 = __importDefault(require("http-errors"));
|
|
9
|
+
const graphql_1 = require("graphql");
|
|
10
|
+
const parseBody_1 = require("./parseBody");
|
|
11
|
+
const renderGraphiQL_1 = require("./renderGraphiQL");
|
|
12
|
+
/**
|
|
13
|
+
* Middleware for express; takes an options object or function as input to
|
|
14
|
+
* configure behavior, and returns an express middleware.
|
|
15
|
+
*/
|
|
16
|
+
function graphqlHTTP(options) {
|
|
17
|
+
devAssert(options != null, 'GraphQL middleware requires options.');
|
|
18
|
+
return async function graphqlMiddleware(request, response) {
|
|
19
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
20
|
+
// Higher scoped variables are referred to at various stages in the asynchronous state machine below.
|
|
21
|
+
let params;
|
|
22
|
+
let showGraphiQL = false;
|
|
23
|
+
let graphiqlOptions;
|
|
24
|
+
let formatErrorFn = graphql_1.formatError;
|
|
25
|
+
let pretty = false;
|
|
26
|
+
let result;
|
|
27
|
+
try {
|
|
28
|
+
// Parse the Request to get GraphQL request parameters.
|
|
29
|
+
try {
|
|
30
|
+
params = await getGraphQLParams(request);
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
// When we failed to parse the GraphQL parameters, we still need to get
|
|
34
|
+
// the options object, so make an options call to resolve just that.
|
|
35
|
+
const optionsData = await resolveOptions();
|
|
36
|
+
pretty = (_a = optionsData.pretty) !== null && _a !== void 0 ? _a : false;
|
|
37
|
+
formatErrorFn = (_c = (_b = optionsData.customFormatErrorFn) !== null && _b !== void 0 ? _b : optionsData.formatError) !== null && _c !== void 0 ? _c : formatErrorFn;
|
|
38
|
+
throw error;
|
|
39
|
+
}
|
|
40
|
+
// Then, resolve the Options to get OptionsData.
|
|
41
|
+
const optionsData = await resolveOptions(params);
|
|
42
|
+
// Collect information from the options data object.
|
|
43
|
+
const schema = optionsData.schema;
|
|
44
|
+
const rootValue = optionsData.rootValue;
|
|
45
|
+
const validationRules = (_d = optionsData.validationRules) !== null && _d !== void 0 ? _d : [];
|
|
46
|
+
const fieldResolver = optionsData.fieldResolver;
|
|
47
|
+
const typeResolver = optionsData.typeResolver;
|
|
48
|
+
const graphiql = (_e = optionsData.graphiql) !== null && _e !== void 0 ? _e : false;
|
|
49
|
+
const extensionsFn = optionsData.extensions;
|
|
50
|
+
const context = (_f = optionsData.context) !== null && _f !== void 0 ? _f : request;
|
|
51
|
+
const parseFn = (_g = optionsData.customParseFn) !== null && _g !== void 0 ? _g : graphql_1.parse;
|
|
52
|
+
const executeFn = (_h = optionsData.customExecuteFn) !== null && _h !== void 0 ? _h : graphql_1.execute;
|
|
53
|
+
const validateFn = (_j = optionsData.customValidateFn) !== null && _j !== void 0 ? _j : graphql_1.validate;
|
|
54
|
+
pretty = (_k = optionsData.pretty) !== null && _k !== void 0 ? _k : false;
|
|
55
|
+
formatErrorFn = (_m = (_l = optionsData.customFormatErrorFn) !== null && _l !== void 0 ? _l : optionsData.formatError) !== null && _m !== void 0 ? _m : formatErrorFn;
|
|
56
|
+
// Assert that schema is required.
|
|
57
|
+
devAssert(schema != null, 'GraphQL middleware options must contain a schema.');
|
|
58
|
+
// GraphQL HTTP only supports GET and POST methods.
|
|
59
|
+
if (request.method !== 'GET' && request.method !== 'POST') {
|
|
60
|
+
throw http_errors_1.default(405, 'GraphQL only supports GET and POST requests.', {
|
|
61
|
+
headers: { Allow: 'GET, POST' },
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
// Get GraphQL params from the request and POST body data.
|
|
65
|
+
const { query, variables, operationName } = params;
|
|
66
|
+
showGraphiQL = canDisplayGraphiQL(request, params) && graphiql !== false;
|
|
67
|
+
if (typeof graphiql !== 'boolean') {
|
|
68
|
+
graphiqlOptions = graphiql;
|
|
69
|
+
}
|
|
70
|
+
// If there is no query, but GraphiQL will be displayed, do not produce
|
|
71
|
+
// a result, otherwise return a 400: Bad Request.
|
|
72
|
+
if (query == null) {
|
|
73
|
+
if (showGraphiQL) {
|
|
74
|
+
return respondWithGraphiQL(response, graphiqlOptions);
|
|
75
|
+
}
|
|
76
|
+
throw http_errors_1.default(400, 'Must provide query string.');
|
|
77
|
+
}
|
|
78
|
+
// Validate Schema
|
|
79
|
+
const schemaValidationErrors = graphql_1.validateSchema(schema);
|
|
80
|
+
if (schemaValidationErrors.length > 0) {
|
|
81
|
+
// Return 500: Internal Server Error if invalid schema.
|
|
82
|
+
throw http_errors_1.default(500, 'GraphQL schema validation error.', {
|
|
83
|
+
graphqlErrors: schemaValidationErrors,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
// Parse source to AST, reporting any syntax error.
|
|
87
|
+
let documentAST;
|
|
88
|
+
try {
|
|
89
|
+
documentAST = parseFn(new graphql_1.Source(query, 'GraphQL request'));
|
|
90
|
+
}
|
|
91
|
+
catch (syntaxError) {
|
|
92
|
+
// Return 400: Bad Request if any syntax errors errors exist.
|
|
93
|
+
throw http_errors_1.default(400, 'GraphQL syntax error.', {
|
|
94
|
+
graphqlErrors: [syntaxError],
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
// Validate AST, reporting any errors.
|
|
98
|
+
const validationErrors = validateFn(schema, documentAST, [
|
|
99
|
+
...graphql_1.specifiedRules,
|
|
100
|
+
...validationRules,
|
|
101
|
+
]);
|
|
102
|
+
if (validationErrors.length > 0) {
|
|
103
|
+
// Return 400: Bad Request if any validation errors exist.
|
|
104
|
+
throw http_errors_1.default(400, 'GraphQL validation error.', {
|
|
105
|
+
graphqlErrors: validationErrors,
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
// Only query operations are allowed on GET requests.
|
|
109
|
+
if (request.method === 'GET') {
|
|
110
|
+
// Determine if this GET request will perform a non-query.
|
|
111
|
+
const operationAST = graphql_1.getOperationAST(documentAST, operationName);
|
|
112
|
+
if (operationAST && operationAST.operation !== 'query') {
|
|
113
|
+
// If GraphiQL can be shown, do not perform this query, but
|
|
114
|
+
// provide it to GraphiQL so that the requester may perform it
|
|
115
|
+
// themselves if desired.
|
|
116
|
+
if (showGraphiQL) {
|
|
117
|
+
return respondWithGraphiQL(response, graphiqlOptions, params);
|
|
118
|
+
}
|
|
119
|
+
// Otherwise, report a 405: Method Not Allowed error.
|
|
120
|
+
throw http_errors_1.default(405, `Can only perform a ${operationAST.operation} operation from a POST request.`, { headers: { Allow: 'POST' } });
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
// Perform the execution, reporting any errors creating the context.
|
|
124
|
+
try {
|
|
125
|
+
result = await executeFn({
|
|
126
|
+
schema,
|
|
127
|
+
document: documentAST,
|
|
128
|
+
rootValue,
|
|
129
|
+
contextValue: context,
|
|
130
|
+
variableValues: variables,
|
|
131
|
+
operationName,
|
|
132
|
+
fieldResolver,
|
|
133
|
+
typeResolver,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
catch (contextError) {
|
|
137
|
+
// Return 400: Bad Request if any execution context errors exist.
|
|
138
|
+
throw http_errors_1.default(400, 'GraphQL execution context error.', {
|
|
139
|
+
graphqlErrors: [contextError],
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
// Collect and apply any metadata extensions if a function was provided.
|
|
143
|
+
// https://graphql.github.io/graphql-spec/#sec-Response-Format
|
|
144
|
+
if (extensionsFn) {
|
|
145
|
+
const extensions = await extensionsFn({
|
|
146
|
+
document: documentAST,
|
|
147
|
+
variables,
|
|
148
|
+
operationName,
|
|
149
|
+
result,
|
|
150
|
+
context,
|
|
151
|
+
});
|
|
152
|
+
if (extensions != null) {
|
|
153
|
+
result = { ...result, extensions };
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
catch (rawError) {
|
|
158
|
+
// If an error was caught, report the httpError status, or 500.
|
|
159
|
+
const error = http_errors_1.default(500,
|
|
160
|
+
/* istanbul ignore next: Thrown by underlying library. */
|
|
161
|
+
rawError instanceof Error ? rawError : String(rawError));
|
|
162
|
+
response.statusCode = error.status;
|
|
163
|
+
const { headers } = error;
|
|
164
|
+
if (headers != null) {
|
|
165
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
166
|
+
response.setHeader(key, String(value));
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
if (error.graphqlErrors == null) {
|
|
170
|
+
const graphqlError = new graphql_1.GraphQLError(error.message, undefined, undefined, undefined, undefined, error);
|
|
171
|
+
result = { data: undefined, errors: [graphqlError] };
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
result = { data: undefined, errors: error.graphqlErrors };
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
// If no data was included in the result, that indicates a runtime query
|
|
178
|
+
// error, indicate as such with a generic status code.
|
|
179
|
+
// Note: Information about the error itself will still be contained in
|
|
180
|
+
// the resulting JSON payload.
|
|
181
|
+
// https://graphql.github.io/graphql-spec/#sec-Data
|
|
182
|
+
if (response.statusCode === 200 && result.data == null) {
|
|
183
|
+
response.statusCode = 500;
|
|
184
|
+
}
|
|
185
|
+
// Format any encountered errors.
|
|
186
|
+
const formattedResult = {
|
|
187
|
+
...result,
|
|
188
|
+
errors: (_o = result.errors) === null || _o === void 0 ? void 0 : _o.map(formatErrorFn),
|
|
189
|
+
};
|
|
190
|
+
// If allowed to show GraphiQL, present it instead of JSON.
|
|
191
|
+
if (showGraphiQL) {
|
|
192
|
+
return respondWithGraphiQL(response, graphiqlOptions, params, formattedResult);
|
|
193
|
+
}
|
|
194
|
+
// If "pretty" JSON isn't requested, and the server provides a
|
|
195
|
+
// response.json method (express), use that directly.
|
|
196
|
+
// Otherwise use the simplified sendResponse method.
|
|
197
|
+
if (!pretty && typeof response.json === 'function') {
|
|
198
|
+
response.json(formattedResult);
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
const payload = JSON.stringify(formattedResult, null, pretty ? 2 : 0);
|
|
202
|
+
sendResponse(response, 'application/json', payload);
|
|
203
|
+
}
|
|
204
|
+
async function resolveOptions(requestParams) {
|
|
205
|
+
const optionsResult = await Promise.resolve(typeof options === 'function'
|
|
206
|
+
? options(request, response, requestParams)
|
|
207
|
+
: options);
|
|
208
|
+
devAssert(optionsResult != null && typeof optionsResult === 'object', 'GraphQL middleware option function must return an options object or a promise which will be resolved to an options object.');
|
|
209
|
+
if (optionsResult.formatError) {
|
|
210
|
+
// eslint-disable-next-line no-console
|
|
211
|
+
console.warn('`formatError` is deprecated and replaced by `customFormatErrorFn`. It will be removed in version 1.0.0.');
|
|
212
|
+
}
|
|
213
|
+
return optionsResult;
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
exports.graphqlHTTP = graphqlHTTP;
|
|
218
|
+
function respondWithGraphiQL(response, options, params, result) {
|
|
219
|
+
const data = {
|
|
220
|
+
query: params === null || params === void 0 ? void 0 : params.query,
|
|
221
|
+
variables: params === null || params === void 0 ? void 0 : params.variables,
|
|
222
|
+
operationName: params === null || params === void 0 ? void 0 : params.operationName,
|
|
223
|
+
result,
|
|
224
|
+
};
|
|
225
|
+
const payload = renderGraphiQL_1.renderGraphiQL(data, options);
|
|
226
|
+
return sendResponse(response, 'text/html', payload);
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Provided a "Request" provided by express or connect (typically a node style
|
|
230
|
+
* HTTPClientRequest), Promise the GraphQL request parameters.
|
|
231
|
+
*/
|
|
232
|
+
async function getGraphQLParams(request) {
|
|
233
|
+
var _a, _b, _c;
|
|
234
|
+
const urlData = new URLSearchParams(request.url.split('?')[1]);
|
|
235
|
+
const bodyData = await parseBody_1.parseBody(request);
|
|
236
|
+
// GraphQL Query string.
|
|
237
|
+
let query = (_a = urlData.get('query')) !== null && _a !== void 0 ? _a : bodyData.query;
|
|
238
|
+
if (typeof query !== 'string') {
|
|
239
|
+
query = null;
|
|
240
|
+
}
|
|
241
|
+
// Parse the variables if needed.
|
|
242
|
+
let variables = ((_b = urlData.get('variables')) !== null && _b !== void 0 ? _b : bodyData.variables);
|
|
243
|
+
if (typeof variables === 'string') {
|
|
244
|
+
try {
|
|
245
|
+
variables = JSON.parse(variables);
|
|
246
|
+
}
|
|
247
|
+
catch (_d) {
|
|
248
|
+
throw http_errors_1.default(400, 'Variables are invalid JSON.');
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
else if (typeof variables !== 'object') {
|
|
252
|
+
variables = null;
|
|
253
|
+
}
|
|
254
|
+
// Name of GraphQL operation to execute.
|
|
255
|
+
let operationName = (_c = urlData.get('operationName')) !== null && _c !== void 0 ? _c : bodyData.operationName;
|
|
256
|
+
if (typeof operationName !== 'string') {
|
|
257
|
+
operationName = null;
|
|
258
|
+
}
|
|
259
|
+
const raw = urlData.get('raw') != null || bodyData.raw !== undefined;
|
|
260
|
+
return { query, variables, operationName, raw };
|
|
261
|
+
}
|
|
262
|
+
exports.getGraphQLParams = getGraphQLParams;
|
|
263
|
+
/**
|
|
264
|
+
* Helper function to determine if GraphiQL can be displayed.
|
|
265
|
+
*/
|
|
266
|
+
function canDisplayGraphiQL(request, params) {
|
|
267
|
+
// If `raw` false, GraphiQL mode is not enabled.
|
|
268
|
+
// Allowed to show GraphiQL if not requested as raw and this request prefers HTML over JSON.
|
|
269
|
+
return !params.raw && accepts_1.default(request).types(['json', 'html']) === 'html';
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Helper function for sending a response using only the core Node server APIs.
|
|
273
|
+
*/
|
|
274
|
+
function sendResponse(response, type, data) {
|
|
275
|
+
const chunk = Buffer.from(data, 'utf8');
|
|
276
|
+
response.setHeader('Content-Type', type + '; charset=utf-8');
|
|
277
|
+
response.setHeader('Content-Length', String(chunk.length));
|
|
278
|
+
response.end(chunk);
|
|
279
|
+
}
|
|
280
|
+
function devAssert(condition, message) {
|
|
281
|
+
const booleanCondition = Boolean(condition);
|
|
282
|
+
if (!booleanCondition) {
|
|
283
|
+
throw new Error(message);
|
|
284
|
+
}
|
|
285
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@depup/express-graphql",
|
|
3
|
+
"version": "0.12.0-depup.0",
|
|
4
|
+
"description": "Production ready GraphQL HTTP middleware. (with updated dependencies)",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"main": "index.js",
|
|
7
|
+
"types": "index.d.ts",
|
|
8
|
+
"typesVersions": {
|
|
9
|
+
"<3.8": {
|
|
10
|
+
"*": [
|
|
11
|
+
"ts3.4/*"
|
|
12
|
+
]
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"sideEffects": false,
|
|
16
|
+
"homepage": "https://github.com/graphql/express-graphql",
|
|
17
|
+
"bugs": {
|
|
18
|
+
"url": "https://github.com/graphql/express-graphql/issues"
|
|
19
|
+
},
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "https://github.com/graphql/express-graphql.git"
|
|
23
|
+
},
|
|
24
|
+
"keywords": [
|
|
25
|
+
"express-graphql",
|
|
26
|
+
"depup",
|
|
27
|
+
"updated-dependencies",
|
|
28
|
+
"security",
|
|
29
|
+
"latest",
|
|
30
|
+
"patched",
|
|
31
|
+
"express",
|
|
32
|
+
"restify",
|
|
33
|
+
"connect",
|
|
34
|
+
"http",
|
|
35
|
+
"graphql",
|
|
36
|
+
"middleware",
|
|
37
|
+
"api"
|
|
38
|
+
],
|
|
39
|
+
"engines": {
|
|
40
|
+
"node": ">= 10.x"
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"accepts": "^1.3.8",
|
|
44
|
+
"content-type": "^1.0.5",
|
|
45
|
+
"http-errors": "^2.0.1",
|
|
46
|
+
"raw-body": "^3.0.2"
|
|
47
|
+
},
|
|
48
|
+
"peerDependencies": {
|
|
49
|
+
"graphql": "^14.7.0 || ^15.3.0"
|
|
50
|
+
},
|
|
51
|
+
"depup": {
|
|
52
|
+
"changes": {
|
|
53
|
+
"accepts": {
|
|
54
|
+
"from": "^1.3.7",
|
|
55
|
+
"to": "^1.3.8"
|
|
56
|
+
},
|
|
57
|
+
"content-type": {
|
|
58
|
+
"from": "^1.0.4",
|
|
59
|
+
"to": "^1.0.5"
|
|
60
|
+
},
|
|
61
|
+
"http-errors": {
|
|
62
|
+
"from": "1.8.0",
|
|
63
|
+
"to": "^2.0.1"
|
|
64
|
+
},
|
|
65
|
+
"raw-body": {
|
|
66
|
+
"from": "^2.4.1",
|
|
67
|
+
"to": "^3.0.2"
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
"depsUpdated": 4,
|
|
71
|
+
"originalPackage": "express-graphql",
|
|
72
|
+
"originalVersion": "0.12.0",
|
|
73
|
+
"processedAt": "2026-03-19T03:01:46.507Z",
|
|
74
|
+
"smokeTest": "passed"
|
|
75
|
+
}
|
|
76
|
+
}
|
package/parseBody.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { IncomingMessage } from 'http';
|
|
3
|
+
declare type Request = IncomingMessage & {
|
|
4
|
+
body?: unknown;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Provided a "Request" provided by express or connect (typically a node style
|
|
8
|
+
* HTTPClientRequest), Promise the body data contained.
|
|
9
|
+
*/
|
|
10
|
+
export declare function parseBody(req: Request): Promise<{
|
|
11
|
+
[param: string]: unknown;
|
|
12
|
+
}>;
|
|
13
|
+
export {};
|