graphql-jit 0.8.9 → 0.9.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 +25 -0
- package/dist/cjs/ast.d.ts +89 -0
- package/dist/cjs/ast.js +766 -0
- package/dist/cjs/ast.js.map +1 -0
- package/dist/cjs/compat.d.ts +70 -0
- package/dist/cjs/compat.js +144 -0
- package/dist/cjs/compat.js.map +1 -0
- package/dist/cjs/debug.d.ts +29 -0
- package/dist/cjs/debug.js +46 -0
- package/dist/cjs/debug.js.map +1 -0
- package/dist/cjs/error.d.ts +7 -0
- package/dist/cjs/error.js +58 -0
- package/dist/cjs/error.js.map +1 -0
- package/dist/cjs/execution.d.ts +154 -0
- package/dist/cjs/execution.js +1240 -0
- package/dist/cjs/execution.js.map +1 -0
- package/dist/cjs/generate.d.ts +4 -0
- package/dist/cjs/generate.js +13 -0
- package/dist/cjs/generate.js.map +1 -0
- package/dist/cjs/index.d.ts +3 -0
- package/dist/cjs/index.js +10 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/inspect.d.ts +5 -0
- package/dist/cjs/inspect.js +110 -0
- package/dist/cjs/inspect.js.map +1 -0
- package/dist/cjs/json.d.ts +9 -0
- package/dist/cjs/json.js +144 -0
- package/dist/cjs/json.js.map +1 -0
- package/dist/cjs/memoize.d.ts +5 -0
- package/dist/cjs/memoize.js +28 -0
- package/dist/cjs/memoize.js.map +1 -0
- package/dist/cjs/non-null.d.ts +9 -0
- package/dist/cjs/non-null.js +205 -0
- package/dist/cjs/non-null.js.map +1 -0
- package/dist/cjs/package.json +3 -0
- package/dist/{resolve-info.d.ts → cjs/resolve-info.d.ts} +10 -12
- package/dist/cjs/resolve-info.js +232 -0
- package/dist/cjs/resolve-info.js.map +1 -0
- package/dist/cjs/runtime.d.ts +14 -0
- package/dist/cjs/runtime.js +92 -0
- package/dist/cjs/runtime.js.map +1 -0
- package/dist/cjs/types.d.ts +1 -0
- package/dist/cjs/types.js +3 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/cjs/variables.d.ts +20 -0
- package/dist/cjs/variables.js +357 -0
- package/dist/cjs/variables.js.map +1 -0
- package/dist/esm/ast.d.ts +89 -0
- package/dist/esm/ast.js +751 -0
- package/dist/esm/ast.js.map +1 -0
- package/dist/esm/compat.d.ts +70 -0
- package/dist/esm/compat.js +102 -0
- package/dist/esm/compat.js.map +1 -0
- package/dist/esm/debug.d.ts +29 -0
- package/dist/esm/debug.js +40 -0
- package/dist/esm/debug.js.map +1 -0
- package/dist/esm/error.d.ts +7 -0
- package/dist/esm/error.js +55 -0
- package/dist/esm/error.js.map +1 -0
- package/dist/esm/execution.d.ts +154 -0
- package/dist/esm/execution.js +1227 -0
- package/dist/esm/execution.js.map +1 -0
- package/dist/esm/generate.d.ts +4 -0
- package/dist/esm/generate.js +10 -0
- package/dist/esm/generate.js.map +1 -0
- package/dist/esm/index.d.ts +3 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/inspect.d.ts +5 -0
- package/dist/esm/inspect.js +106 -0
- package/dist/esm/inspect.js.map +1 -0
- package/dist/esm/json.d.ts +9 -0
- package/dist/esm/json.js +141 -0
- package/dist/esm/json.js.map +1 -0
- package/dist/esm/memoize.d.ts +5 -0
- package/dist/esm/memoize.js +20 -0
- package/dist/esm/memoize.js.map +1 -0
- package/dist/esm/non-null.d.ts +9 -0
- package/dist/esm/non-null.js +199 -0
- package/dist/esm/non-null.js.map +1 -0
- package/dist/esm/package.json +3 -0
- package/dist/{resolve-info.d.mts → esm/resolve-info.d.ts} +10 -12
- package/dist/esm/resolve-info.js +224 -0
- package/dist/esm/resolve-info.js.map +1 -0
- package/dist/esm/runtime.d.ts +14 -0
- package/dist/esm/runtime.js +89 -0
- package/dist/esm/runtime.js.map +1 -0
- package/dist/esm/types.d.ts +1 -0
- package/dist/esm/types.js +2 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/variables.d.ts +20 -0
- package/dist/esm/variables.js +350 -0
- package/dist/esm/variables.js.map +1 -0
- package/package.json +39 -35
- package/dist/ast.d.mts +0 -7
- package/dist/ast.d.ts +0 -7
- package/dist/ast.js +0 -635
- package/dist/ast.js.map +0 -1
- package/dist/ast.mjs +0 -612
- package/dist/ast.mjs.map +0 -1
- package/dist/compat.d.mts +0 -7
- package/dist/compat.d.ts +0 -7
- package/dist/compat.js +0 -113
- package/dist/compat.js.map +0 -1
- package/dist/compat.mjs +0 -75
- package/dist/compat.mjs.map +0 -1
- package/dist/error.d.mts +0 -11
- package/dist/error.d.ts +0 -11
- package/dist/error.js +0 -79
- package/dist/error.js.map +0 -1
- package/dist/error.mjs +0 -57
- package/dist/error.mjs.map +0 -1
- package/dist/execution.d.mts +0 -7
- package/dist/execution.d.ts +0 -7
- package/dist/execution.js +0 -1262
- package/dist/execution.js.map +0 -1
- package/dist/execution.mjs +0 -1248
- package/dist/execution.mjs.map +0 -1
- package/dist/generate.d.mts +0 -6
- package/dist/generate.d.ts +0 -6
- package/dist/generate.js +0 -37
- package/dist/generate.js.map +0 -1
- package/dist/generate.mjs +0 -13
- package/dist/generate.mjs.map +0 -1
- package/dist/index-CeluTkd4.d.mts +0 -329
- package/dist/index-mKv2zpdA.d.ts +0 -329
- package/dist/index.d.mts +0 -7
- package/dist/index.d.ts +0 -7
- package/dist/index.js +0 -36
- package/dist/index.js.map +0 -1
- package/dist/index.mjs +0 -15
- package/dist/index.mjs.map +0 -1
- package/dist/inspect.d.mts +0 -7
- package/dist/inspect.d.ts +0 -7
- package/dist/inspect.js +0 -121
- package/dist/inspect.js.map +0 -1
- package/dist/inspect.mjs +0 -97
- package/dist/inspect.mjs.map +0 -1
- package/dist/json.d.mts +0 -18
- package/dist/json.d.ts +0 -18
- package/dist/json.js +0 -181
- package/dist/json.js.map +0 -1
- package/dist/json.mjs +0 -164
- package/dist/json.mjs.map +0 -1
- package/dist/memoize.d.mts +0 -6
- package/dist/memoize.d.ts +0 -6
- package/dist/memoize.js +0 -67
- package/dist/memoize.js.map +0 -1
- package/dist/memoize.mjs +0 -31
- package/dist/memoize.mjs.map +0 -1
- package/dist/non-null.d.mts +0 -7
- package/dist/non-null.d.ts +0 -7
- package/dist/non-null.js +0 -196
- package/dist/non-null.js.map +0 -1
- package/dist/non-null.mjs +0 -167
- package/dist/non-null.mjs.map +0 -1
- package/dist/resolve-info.js +0 -245
- package/dist/resolve-info.js.map +0 -1
- package/dist/resolve-info.mjs +0 -219
- package/dist/resolve-info.mjs.map +0 -1
- package/dist/runtime.d.mts +0 -7
- package/dist/runtime.d.ts +0 -7
- package/dist/runtime.js +0 -115
- package/dist/runtime.js.map +0 -1
- package/dist/runtime.mjs +0 -91
- package/dist/runtime.mjs.map +0 -1
- package/dist/types.d.mts +0 -3
- package/dist/types.d.ts +0 -3
- package/dist/types.js +0 -17
- package/dist/types.js.map +0 -1
- package/dist/types.mjs +0 -1
- package/dist/types.mjs.map +0 -1
- package/dist/variables.d.mts +0 -17
- package/dist/variables.d.ts +0 -17
- package/dist/variables.js +0 -412
- package/dist/variables.js.map +0 -1
- package/dist/variables.mjs +0 -391
- package/dist/variables.mjs.map +0 -1
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.jitRuntime = void 0;
|
|
4
|
+
function resolvePromise(ctx, promise, onSuccess, onError) {
|
|
5
|
+
++ctx.promiseCounter;
|
|
6
|
+
promise.then((result) => {
|
|
7
|
+
onSuccess(result);
|
|
8
|
+
--ctx.promiseCounter;
|
|
9
|
+
if (ctx.promiseCounter === 0)
|
|
10
|
+
ctx.resolve(ctx);
|
|
11
|
+
}, (err) => {
|
|
12
|
+
onError(err);
|
|
13
|
+
--ctx.promiseCounter;
|
|
14
|
+
if (ctx.promiseCounter === 0)
|
|
15
|
+
ctx.resolve(ctx);
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
exports.jitRuntime = {
|
|
19
|
+
isPromise(value) {
|
|
20
|
+
return (value != null &&
|
|
21
|
+
typeof value === "object" &&
|
|
22
|
+
typeof value.then === "function");
|
|
23
|
+
},
|
|
24
|
+
checkNonNullLeaf(ctx, value, dest, nullMsg, locs, path, capStack, serialize, errHandler, ...parentIndexes) {
|
|
25
|
+
const GQLError = ctx.GraphQLError;
|
|
26
|
+
if (value == null) {
|
|
27
|
+
dest.push(new GQLError(nullMsg, locs, path, undefined, capStack));
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
if (value instanceof Error) {
|
|
31
|
+
dest.push(new GQLError(value.message ?? value, locs, path, value, capStack));
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
return serialize(ctx, value, errHandler, ...parentIndexes);
|
|
35
|
+
},
|
|
36
|
+
checkNullableLeaf(ctx, value, dest, locs, path, capStack, serialize, errHandler, ...parentIndexes) {
|
|
37
|
+
if (value == null)
|
|
38
|
+
return null;
|
|
39
|
+
const GQLError = ctx.GraphQLError;
|
|
40
|
+
if (value instanceof Error) {
|
|
41
|
+
dest.push(new GQLError(value.message ?? value, locs, path, value, capStack));
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
return serialize(ctx, value, errHandler, ...parentIndexes);
|
|
45
|
+
},
|
|
46
|
+
callResolver(ctx, call, onSuccess, onError) {
|
|
47
|
+
let value;
|
|
48
|
+
try {
|
|
49
|
+
value = call();
|
|
50
|
+
}
|
|
51
|
+
catch (err) {
|
|
52
|
+
onError(err);
|
|
53
|
+
onSuccess(null);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
this.handleResolverResult(ctx, value, onSuccess, onError);
|
|
57
|
+
},
|
|
58
|
+
handleResolverResult(ctx, value, onSuccess, onError) {
|
|
59
|
+
if (this.isPromise(value)) {
|
|
60
|
+
resolvePromise(ctx, value, onSuccess, onError);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
onSuccess(value);
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
handleListItemResult(ctx, item, onSuccess, onError) {
|
|
67
|
+
if (this.isPromise(item)) {
|
|
68
|
+
resolvePromise(ctx, item, onSuccess, onError);
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
onSuccess(item);
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
finalizeResult(ctx) {
|
|
75
|
+
if (ctx.promiseCounter > 0) {
|
|
76
|
+
return new Promise((resolve) => {
|
|
77
|
+
ctx.resolve = resolve;
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
return undefined;
|
|
81
|
+
},
|
|
82
|
+
safeMap(ctx, iterable, cb, ...idx) {
|
|
83
|
+
let index = 0;
|
|
84
|
+
const result = [];
|
|
85
|
+
for (const a of iterable) {
|
|
86
|
+
cb(ctx, a, index, result, ...idx);
|
|
87
|
+
++index;
|
|
88
|
+
}
|
|
89
|
+
return result;
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
//# sourceMappingURL=runtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.js","sourceRoot":"","sources":["../../src/runtime.ts"],"names":[],"mappings":";;;AASA,SAAS,cAAc,CACrB,GAAqB,EACrB,OAAyB,EACzB,SAAoC,EACpC,OAA+B;IAE/B,EAAE,GAAG,CAAC,cAAc,CAAC;IACrB,OAAO,CAAC,IAAI,CACV,CAAC,MAAM,EAAE,EAAE;QACT,SAAS,CAAC,MAAM,CAAC,CAAC;QAClB,EAAE,GAAG,CAAC,cAAc,CAAC;QACrB,IAAI,GAAG,CAAC,cAAc,KAAK,CAAC;YAAE,GAAG,CAAC,OAAQ,CAAC,GAAG,CAAC,CAAC;IAClD,CAAC,EACD,CAAC,GAAG,EAAE,EAAE;QACN,OAAO,CAAC,GAAG,CAAC,CAAC;QACb,EAAE,GAAG,CAAC,cAAc,CAAC;QACrB,IAAI,GAAG,CAAC,cAAc,KAAK,CAAC;YAAE,GAAG,CAAC,OAAQ,CAAC,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AAG,CAAC,cAAc,GAAG,CAAC,EAAE,CAAC;YAC3B,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;gBAC7B,GAAG,CAAC,OAAO,GAAG,OAAO,CAAC;YACxB,CAAC,CAAC,CAAC;QACL,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,OAAO,CACL,GAAqB,EACrB,QAAoC,EACpC,EAMS,EACT,GAAG,GAAa;QAEhB,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,MAAM,MAAM,GAAc,EAAE,CAAC;QAC7B,KAAK,MAAM,CAAC,IAAI,QAA6B,EAAE,CAAC;YAC9C,EAAE,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC,CAAC;YAClC,EAAE,KAAK,CAAC;QACV,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF,CAAC","sourcesContent":["import { type ExecutionContext } from \"./execution.js\";\n\ntype Serializer = (\n c: ExecutionContext,\n v: any,\n onError: any,\n ...idx: number[]\n) => any;\n\nfunction resolvePromise(\n ctx: ExecutionContext,\n promise: Promise<unknown>,\n onSuccess: (result: unknown) => void,\n onError: (err: unknown) => void\n): void {\n ++ctx.promiseCounter;\n promise.then(\n (result) => {\n onSuccess(result);\n --ctx.promiseCounter;\n if (ctx.promiseCounter === 0) ctx.resolve!(ctx);\n },\n (err) => {\n onError(err);\n --ctx.promiseCounter;\n if (ctx.promiseCounter === 0) ctx.resolve!(ctx);\n }\n );\n}\n\nexport const jitRuntime = {\n isPromise(value: unknown): boolean {\n return (\n value != null &&\n typeof value === \"object\" &&\n typeof (value as any).then === \"function\"\n );\n },\n\n checkNonNullLeaf(\n ctx: ExecutionContext,\n value: unknown,\n dest: any[],\n nullMsg: string,\n locs: any,\n path: any,\n capStack: boolean,\n serialize: Serializer,\n errHandler: any,\n ...parentIndexes: number[]\n ): any {\n const GQLError = ctx.GraphQLError as any;\n if (value == null) {\n dest.push(new GQLError(nullMsg, locs, path, undefined, capStack));\n return null;\n }\n if (value instanceof Error) {\n dest.push(\n new GQLError(value.message ?? value, locs, path, value, capStack)\n );\n return null;\n }\n return serialize(ctx, value, errHandler, ...parentIndexes);\n },\n\n checkNullableLeaf(\n ctx: ExecutionContext,\n value: unknown,\n dest: any[],\n locs: any,\n path: any,\n capStack: boolean,\n serialize: Serializer,\n errHandler: any,\n ...parentIndexes: number[]\n ): any {\n if (value == null) return null;\n const GQLError = ctx.GraphQLError as any;\n if (value instanceof Error) {\n dest.push(\n new GQLError(value.message ?? value, locs, path, value, capStack)\n );\n return null;\n }\n return serialize(ctx, value, errHandler, ...parentIndexes);\n },\n\n callResolver(\n ctx: ExecutionContext,\n call: () => unknown,\n onSuccess: (result: unknown) => void,\n onError: (err: unknown) => void\n ): void {\n let value: unknown;\n try {\n value = call();\n } catch (err) {\n onError(err);\n onSuccess(null);\n return;\n }\n this.handleResolverResult(ctx, value, onSuccess, onError);\n },\n\n handleResolverResult(\n ctx: ExecutionContext,\n value: unknown,\n onSuccess: (result: unknown) => void,\n onError: (err: unknown) => void\n ): void {\n if (this.isPromise(value)) {\n resolvePromise(ctx, value as Promise<unknown>, onSuccess, onError);\n } else {\n onSuccess(value);\n }\n },\n\n handleListItemResult(\n ctx: ExecutionContext,\n item: unknown,\n onSuccess: (result: unknown) => void,\n onError: (err: unknown) => void\n ): void {\n if (this.isPromise(item)) {\n resolvePromise(ctx, item as Promise<unknown>, onSuccess, onError);\n } else {\n onSuccess(item);\n }\n },\n\n finalizeResult(ctx: ExecutionContext): Promise<unknown> | undefined {\n if (ctx.promiseCounter > 0) {\n return new Promise((resolve) => {\n ctx.resolve = resolve;\n });\n }\n return undefined;\n },\n\n safeMap(\n ctx: ExecutionContext,\n iterable: Iterable<unknown> | string,\n cb: (\n context: ExecutionContext,\n a: unknown,\n index: number,\n resultArray: unknown[],\n ...idx: number[]\n ) => void,\n ...idx: number[]\n ): unknown[] {\n let index = 0;\n const result: unknown[] = [];\n for (const a of iterable as Iterable<unknown>) {\n cb(ctx, a, index, result, ...idx);\n ++index;\n }\n return result;\n }\n};\n\nexport type JitRuntime = typeof jitRuntime;\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type Maybe<T> = null | undefined | T;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"","sourcesContent":["// Vendored version of the Maybe type from graphql so we can support different graphql versions where it has moved around\nexport type Maybe<T> = null | undefined | T;\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { GraphQLError, GraphQLSchema, type OperationDefinitionNode, type VariableDefinitionNode } from "graphql";
|
|
2
|
+
import { type CompilerDebugOptions } from "./debug.js";
|
|
3
|
+
interface FailedVariableCoercion {
|
|
4
|
+
errors: ReadonlyArray<GraphQLError>;
|
|
5
|
+
}
|
|
6
|
+
interface VariableValues {
|
|
7
|
+
coerced: {
|
|
8
|
+
[key: string]: any;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export type CoercedVariableValues = FailedVariableCoercion | VariableValues;
|
|
12
|
+
export declare function failToParseVariables(x: any): x is FailedVariableCoercion;
|
|
13
|
+
interface VariableCompilationDebugOptions {
|
|
14
|
+
compilerOptions: CompilerDebugOptions;
|
|
15
|
+
operation: OperationDefinitionNode;
|
|
16
|
+
}
|
|
17
|
+
export declare function compileVariableParsing(schema: GraphQLSchema, varDefNodes: ReadonlyArray<VariableDefinitionNode>, debug?: VariableCompilationDebugOptions): (inputs: {
|
|
18
|
+
[key: string]: any;
|
|
19
|
+
}) => CoercedVariableValues;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,357 @@
|
|
|
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.failToParseVariables = failToParseVariables;
|
|
7
|
+
exports.compileVariableParsing = compileVariableParsing;
|
|
8
|
+
const generate_js_1 = require("./generate.js");
|
|
9
|
+
const graphql_1 = require("graphql");
|
|
10
|
+
const ast_js_1 = require("./ast.js");
|
|
11
|
+
const error_js_1 = require("./error.js");
|
|
12
|
+
const compat_js_1 = require("./compat.js");
|
|
13
|
+
const inspect_js_1 = __importDefault(require("./inspect.js"));
|
|
14
|
+
const debug_js_1 = require("./debug.js");
|
|
15
|
+
const inspect = (0, inspect_js_1.default)();
|
|
16
|
+
function failToParseVariables(x) {
|
|
17
|
+
return x.errors;
|
|
18
|
+
}
|
|
19
|
+
function createSubCompilationContext(context) {
|
|
20
|
+
return { ...context };
|
|
21
|
+
}
|
|
22
|
+
function compileVariableParsing(schema, varDefNodes, debug) {
|
|
23
|
+
const errors = [];
|
|
24
|
+
const coercedValues = Object.create(null);
|
|
25
|
+
let mainBody = "";
|
|
26
|
+
const dependencies = new Map();
|
|
27
|
+
for (const varDefNode of varDefNodes) {
|
|
28
|
+
const context = {
|
|
29
|
+
varDefNode,
|
|
30
|
+
depth: 0,
|
|
31
|
+
inputPath: (0, ast_js_1.addPath)(undefined, "input"),
|
|
32
|
+
responsePath: (0, ast_js_1.addPath)(undefined, "coerced"),
|
|
33
|
+
dependencies
|
|
34
|
+
};
|
|
35
|
+
const varName = varDefNode.variable.name.value;
|
|
36
|
+
const varType = (0, graphql_1.typeFromAST)(schema, varDefNode.type);
|
|
37
|
+
if (!varType || !(0, graphql_1.isInputType)(varType)) {
|
|
38
|
+
// Must use input types for variables. This should be caught during
|
|
39
|
+
// validation, however is checked again here for safety.
|
|
40
|
+
errors.push(new error_js_1.GraphQLError(`Variable "$${varName}" expected value of type ` +
|
|
41
|
+
`"${varType || (0, graphql_1.print)(varDefNode.type)}" which cannot be used as an input type.`, (0, ast_js_1.computeLocations)([varDefNode.type])));
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
// Ensure a constant shape of the input map
|
|
45
|
+
coercedValues[varName] = undefined;
|
|
46
|
+
const hasValueName = hasValue((0, ast_js_1.addPath)(context.inputPath, varName));
|
|
47
|
+
mainBody += `const ${hasValueName} = Object.prototype.hasOwnProperty.call(${getObjectPath(context.inputPath)}, "${varName}");\n`;
|
|
48
|
+
context.inputPath = (0, ast_js_1.addPath)(context.inputPath, varName);
|
|
49
|
+
context.responsePath = (0, ast_js_1.addPath)(context.responsePath, varName);
|
|
50
|
+
mainBody += generateInput(context, varType, varName, hasValueName, (0, graphql_1.valueFromAST)(varDefNode.defaultValue, varType), false);
|
|
51
|
+
}
|
|
52
|
+
if (errors.length > 0) {
|
|
53
|
+
throw errors;
|
|
54
|
+
}
|
|
55
|
+
const gen = (0, generate_js_1.genFn)();
|
|
56
|
+
gen(`function getVariables(input) {
|
|
57
|
+
const errors = [];
|
|
58
|
+
const coerced = ${JSON.stringify(coercedValues)}
|
|
59
|
+
${mainBody}
|
|
60
|
+
if (errors.length > 0) {
|
|
61
|
+
return {errors, coerced: undefined};
|
|
62
|
+
}
|
|
63
|
+
return {errors: undefined, coerced};
|
|
64
|
+
}
|
|
65
|
+
`);
|
|
66
|
+
const functionExpression = gen.toString();
|
|
67
|
+
const functionBody = debug
|
|
68
|
+
? "return " +
|
|
69
|
+
(0, debug_js_1.formatDebugSource)(functionExpression, debug.compilerOptions.formatSourceCode)
|
|
70
|
+
: `
|
|
71
|
+
return ${functionExpression}`;
|
|
72
|
+
const generatedSource = debug
|
|
73
|
+
? (0, debug_js_1.appendSourceURL)(functionBody, (0, debug_js_1.createGeneratedSourceName)(debug.operation.name?.value, debug.compilerOptions, "variables"))
|
|
74
|
+
: functionBody;
|
|
75
|
+
// eslint-disable-next-line
|
|
76
|
+
return Function.apply(null, ["GraphQLJITError", "inspect"]
|
|
77
|
+
.concat(Array.from(dependencies.keys()))
|
|
78
|
+
.concat(generatedSource)).apply(null, [error_js_1.GraphQLError, inspect].concat(Array.from(dependencies.values())));
|
|
79
|
+
}
|
|
80
|
+
// Int Scalars represent 32 bits
|
|
81
|
+
// https://graphql.github.io/graphql-spec/June2018/#sec-Int
|
|
82
|
+
const MAX_32BIT_INT = 2147483647;
|
|
83
|
+
const MIN_32BIT_INT = -2147483648;
|
|
84
|
+
function generateInput(context, varType, varName, hasValueName, defaultValue, wrapInList) {
|
|
85
|
+
const currentOutput = getObjectPath(context.responsePath);
|
|
86
|
+
const currentInput = getObjectPath(context.inputPath);
|
|
87
|
+
const errorLocation = printErrorLocation((0, ast_js_1.computeLocations)([context.varDefNode]));
|
|
88
|
+
const gen = (0, generate_js_1.genFn)();
|
|
89
|
+
gen(`if (${currentInput} == null) {`);
|
|
90
|
+
if ((0, graphql_1.isNonNullType)(varType)) {
|
|
91
|
+
let nonNullMessage;
|
|
92
|
+
let omittedMessage;
|
|
93
|
+
if (context.errorMessage) {
|
|
94
|
+
const objectPath = printObjectPath(context.responsePath);
|
|
95
|
+
nonNullMessage = `${context.errorMessage} + \`Expected non-nullable type ${varType} not to be null at ${objectPath}.\``;
|
|
96
|
+
omittedMessage = `${context.errorMessage} + \`Field ${objectPath} of required type ${varType} was not provided.\``;
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
nonNullMessage = `'Variable "$${varName}" of non-null type "${varType}" must not be null.'`;
|
|
100
|
+
omittedMessage = `'Variable "$${varName}" of required type "${varType}" was not provided.'`;
|
|
101
|
+
}
|
|
102
|
+
varType = varType.ofType;
|
|
103
|
+
gen(`
|
|
104
|
+
if (${currentOutput} == null) {
|
|
105
|
+
errors.push(new GraphQLJITError(${hasValueName} ? ${nonNullMessage} : ${omittedMessage}, ${errorLocation}));
|
|
106
|
+
}
|
|
107
|
+
`);
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
gen(`
|
|
111
|
+
if (${hasValueName}) { ${currentOutput} = null; }
|
|
112
|
+
`);
|
|
113
|
+
if (defaultValue !== undefined) {
|
|
114
|
+
gen(`else { ${currentOutput} = ${JSON.stringify(defaultValue)} }`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
gen(`} else {`);
|
|
118
|
+
if ((0, graphql_1.isScalarType)(varType)) {
|
|
119
|
+
switch (varType.name) {
|
|
120
|
+
case graphql_1.GraphQLID.name:
|
|
121
|
+
gen(`
|
|
122
|
+
if (typeof ${currentInput} === "string") {
|
|
123
|
+
${currentOutput} = ${currentInput};
|
|
124
|
+
} else if (Number.isInteger(${currentInput})) {
|
|
125
|
+
${currentOutput} = ${currentInput}.toString();
|
|
126
|
+
} else {
|
|
127
|
+
errors.push(new GraphQLJITError('Variable "$${varName}" got invalid value ' +
|
|
128
|
+
inspect(${currentInput}) + "; " +
|
|
129
|
+
'Expected type ${varType.name}; ' +
|
|
130
|
+
'${varType.name} cannot represent value: ' +
|
|
131
|
+
inspect(${currentInput}), ${errorLocation})
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
`);
|
|
135
|
+
break;
|
|
136
|
+
case graphql_1.GraphQLString.name:
|
|
137
|
+
gen(`
|
|
138
|
+
if (typeof ${currentInput} === "string") {
|
|
139
|
+
${currentOutput} = ${currentInput};
|
|
140
|
+
} else {
|
|
141
|
+
errors.push(new GraphQLJITError('Variable "$${varName}" got invalid value ' +
|
|
142
|
+
inspect(${currentInput}) + "; " +
|
|
143
|
+
'Expected type ${varType.name}; ' +
|
|
144
|
+
'${varType.name} cannot represent a non string value: ' +
|
|
145
|
+
inspect(${currentInput}), ${errorLocation})
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
`);
|
|
149
|
+
break;
|
|
150
|
+
case graphql_1.GraphQLBoolean.name:
|
|
151
|
+
gen(`
|
|
152
|
+
if (typeof ${currentInput} === "boolean") {
|
|
153
|
+
${currentOutput} = ${currentInput};
|
|
154
|
+
} else {
|
|
155
|
+
errors.push(new GraphQLJITError('Variable "$${varName}" got invalid value ' +
|
|
156
|
+
inspect(${currentInput}) + "; " +
|
|
157
|
+
'Expected type ${varType.name}; ' +
|
|
158
|
+
'${varType.name} cannot represent a non boolean value: ' +
|
|
159
|
+
inspect(${currentInput}), ${errorLocation}));
|
|
160
|
+
}
|
|
161
|
+
`);
|
|
162
|
+
break;
|
|
163
|
+
case graphql_1.GraphQLInt.name:
|
|
164
|
+
gen(`
|
|
165
|
+
if (Number.isInteger(${currentInput})) {
|
|
166
|
+
if (${currentInput} > ${MAX_32BIT_INT} || ${currentInput} < ${MIN_32BIT_INT}) {
|
|
167
|
+
errors.push(new GraphQLJITError('Variable "$${varName}" got invalid value ' +
|
|
168
|
+
inspect(${currentInput}) + "; " +
|
|
169
|
+
'Expected type ${varType.name}; ' +
|
|
170
|
+
'${varType.name} cannot represent non 32-bit signed integer value: ' +
|
|
171
|
+
inspect(${currentInput}), ${errorLocation}));
|
|
172
|
+
} else {
|
|
173
|
+
${currentOutput} = ${currentInput};
|
|
174
|
+
}
|
|
175
|
+
} else {
|
|
176
|
+
errors.push(new GraphQLJITError('Variable "$${varName}" got invalid value ' +
|
|
177
|
+
inspect(${currentInput}) + "; " +
|
|
178
|
+
'Expected type ${varType.name}; ' +
|
|
179
|
+
'${varType.name} cannot represent non-integer value: ' +
|
|
180
|
+
inspect(${currentInput}), ${errorLocation})
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
`);
|
|
184
|
+
break;
|
|
185
|
+
case graphql_1.GraphQLFloat.name:
|
|
186
|
+
gen(`
|
|
187
|
+
if (Number.isFinite(${currentInput})) {
|
|
188
|
+
${currentOutput} = ${currentInput};
|
|
189
|
+
} else {
|
|
190
|
+
errors.push(new GraphQLJITError('Variable "$${varName}" got invalid value ' +
|
|
191
|
+
inspect(${currentInput}) + "; " +
|
|
192
|
+
'Expected type ${varType.name}; ' +
|
|
193
|
+
'${varType.name} cannot represent non numeric value: ' +
|
|
194
|
+
inspect(${currentInput}), ${errorLocation})
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
`);
|
|
198
|
+
break;
|
|
199
|
+
default:
|
|
200
|
+
context.dependencies.set(`${varType.name}parseValue`, varType.parseValue.bind(varType));
|
|
201
|
+
gen(`
|
|
202
|
+
try {
|
|
203
|
+
const parseResult = ${varType.name}parseValue(${currentInput});
|
|
204
|
+
if (parseResult === undefined || parseResult !== parseResult) {
|
|
205
|
+
errors.push(new GraphQLJITError('Variable "$${varName}" got invalid value ' +
|
|
206
|
+
inspect(${currentInput}) + "; " +
|
|
207
|
+
'Expected type ${varType.name}.', ${errorLocation}));
|
|
208
|
+
}
|
|
209
|
+
${currentOutput} = parseResult;
|
|
210
|
+
} catch (error) {
|
|
211
|
+
errors.push(new GraphQLJITError('Variable "$${varName}" got invalid value ' +
|
|
212
|
+
inspect(${currentInput}) + "; " +
|
|
213
|
+
'Expected type ${varType.name}.', ${errorLocation}, undefined, error)
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
`);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
else if ((0, graphql_1.isEnumType)(varType)) {
|
|
220
|
+
context.dependencies.set(`${varType.name}getValue`, varType.getValue.bind(varType));
|
|
221
|
+
gen(`
|
|
222
|
+
if (typeof ${currentInput} === "string") {
|
|
223
|
+
const enumValue = ${varType.name}getValue(${currentInput});
|
|
224
|
+
if (enumValue) {
|
|
225
|
+
${currentOutput} = enumValue.value;
|
|
226
|
+
} else {
|
|
227
|
+
errors.push(
|
|
228
|
+
new GraphQLJITError('Variable "$${varName}" got invalid value ' +
|
|
229
|
+
inspect(${currentInput}) + "; " +
|
|
230
|
+
'Expected type ${varType.name}.', ${errorLocation})
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
} else {
|
|
234
|
+
errors.push(
|
|
235
|
+
new GraphQLJITError('Variable "$${varName}" got invalid value ' +
|
|
236
|
+
inspect(${currentInput}) + "; " +
|
|
237
|
+
'Expected type ${varType.name}.', ${errorLocation})
|
|
238
|
+
);
|
|
239
|
+
}
|
|
240
|
+
`);
|
|
241
|
+
}
|
|
242
|
+
else if ((0, graphql_1.isListType)(varType)) {
|
|
243
|
+
context.errorMessage = `'Variable "$${varName}" got invalid value ' + inspect(${currentInput}) + '; '`;
|
|
244
|
+
const hasValueName = hasValue(context.inputPath);
|
|
245
|
+
const index = `idx${context.depth}`;
|
|
246
|
+
const subContext = createSubCompilationContext(context);
|
|
247
|
+
subContext.responsePath = (0, ast_js_1.addPath)(subContext.responsePath, index, "variable");
|
|
248
|
+
subContext.inputPath = (0, ast_js_1.addPath)(subContext.inputPath, index, "variable");
|
|
249
|
+
subContext.depth++;
|
|
250
|
+
gen(`
|
|
251
|
+
if (Array.isArray(${currentInput})) {
|
|
252
|
+
${currentOutput} = [];
|
|
253
|
+
for (let ${index} = 0; ${index} < ${currentInput}.length; ++${index}) {
|
|
254
|
+
const ${hasValueName} =
|
|
255
|
+
${getObjectPath(subContext.inputPath)} !== undefined;
|
|
256
|
+
${generateInput(subContext, varType.ofType, varName, hasValueName, undefined, false)}
|
|
257
|
+
}
|
|
258
|
+
} else {
|
|
259
|
+
${generateInput(context, varType.ofType, varName, hasValueName, undefined, true)}
|
|
260
|
+
}
|
|
261
|
+
`);
|
|
262
|
+
}
|
|
263
|
+
else if ((0, graphql_1.isInputType)(varType)) {
|
|
264
|
+
gen(`
|
|
265
|
+
if (typeof ${currentInput} !== 'object') {
|
|
266
|
+
errors.push(new GraphQLJITError('Variable "$${varName}" got invalid value ' +
|
|
267
|
+
inspect(${currentInput}) + "; " +
|
|
268
|
+
'Expected type ${varType.name} to be an object.', ${errorLocation}));
|
|
269
|
+
} else {
|
|
270
|
+
${currentOutput} = {};
|
|
271
|
+
`);
|
|
272
|
+
const fields = varType.getFields();
|
|
273
|
+
const allowedFields = [];
|
|
274
|
+
for (const field of Object.values(fields)) {
|
|
275
|
+
const subContext = createSubCompilationContext(context);
|
|
276
|
+
allowedFields.push(field.name);
|
|
277
|
+
const hasValueName = hasValue((0, ast_js_1.addPath)(subContext.inputPath, field.name));
|
|
278
|
+
gen(`
|
|
279
|
+
const ${hasValueName} = Object.prototype.hasOwnProperty.call(
|
|
280
|
+
${getObjectPath(subContext.inputPath)}, "${field.name}"
|
|
281
|
+
);
|
|
282
|
+
`);
|
|
283
|
+
subContext.inputPath = (0, ast_js_1.addPath)(subContext.inputPath, field.name);
|
|
284
|
+
subContext.responsePath = (0, ast_js_1.addPath)(subContext.responsePath, field.name);
|
|
285
|
+
subContext.errorMessage = `'Variable "$${varName}" got invalid value ' + inspect(${currentInput}) + '; '`;
|
|
286
|
+
gen(`
|
|
287
|
+
${generateInput(subContext, field.type, field.name, hasValueName, (0, compat_js_1.hasDefaultValue)(field) ? (0, compat_js_1.getDefaultValue)(field) : undefined, false)}
|
|
288
|
+
`);
|
|
289
|
+
}
|
|
290
|
+
gen(`
|
|
291
|
+
const allowedFields = ${JSON.stringify(allowedFields)};
|
|
292
|
+
for (const fieldName of Object.keys(${currentInput})) {
|
|
293
|
+
if (!allowedFields.includes(fieldName)) {
|
|
294
|
+
errors.push(new GraphQLJITError('Variable "$${varName}" got invalid value ' +
|
|
295
|
+
inspect(${currentInput}) + "; " +
|
|
296
|
+
'Field "' + fieldName + '" is not defined by type ${varType.name}.', ${errorLocation}));
|
|
297
|
+
break;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}`);
|
|
301
|
+
}
|
|
302
|
+
else {
|
|
303
|
+
/* istanbul ignore next line */
|
|
304
|
+
throw new Error(`unknown type: ${varType}`);
|
|
305
|
+
}
|
|
306
|
+
if (wrapInList) {
|
|
307
|
+
gen(`${currentOutput} = [${currentOutput}];`);
|
|
308
|
+
}
|
|
309
|
+
gen(`}`);
|
|
310
|
+
return gen.toString();
|
|
311
|
+
}
|
|
312
|
+
function hasValue(path) {
|
|
313
|
+
const flattened = [];
|
|
314
|
+
let curr = path;
|
|
315
|
+
while (curr) {
|
|
316
|
+
flattened.push(curr.key);
|
|
317
|
+
curr = curr.prev;
|
|
318
|
+
}
|
|
319
|
+
return `hasValue${flattened.join("_")}`;
|
|
320
|
+
}
|
|
321
|
+
function printErrorLocation(location) {
|
|
322
|
+
return JSON.stringify(location);
|
|
323
|
+
}
|
|
324
|
+
function getObjectPath(path) {
|
|
325
|
+
const flattened = [];
|
|
326
|
+
let curr = path;
|
|
327
|
+
while (curr) {
|
|
328
|
+
flattened.unshift({ key: curr.key, type: curr.type });
|
|
329
|
+
curr = curr.prev;
|
|
330
|
+
}
|
|
331
|
+
let name = flattened[0].key;
|
|
332
|
+
for (let i = 1; i < flattened.length; ++i) {
|
|
333
|
+
name +=
|
|
334
|
+
flattened[i].type === "literal"
|
|
335
|
+
? `["${flattened[i].key}"]`
|
|
336
|
+
: `[${flattened[i].key}]`;
|
|
337
|
+
}
|
|
338
|
+
return name;
|
|
339
|
+
}
|
|
340
|
+
function printObjectPath(path) {
|
|
341
|
+
const flattened = [];
|
|
342
|
+
let curr = path;
|
|
343
|
+
while (curr) {
|
|
344
|
+
flattened.unshift({ key: curr.key, type: curr.type });
|
|
345
|
+
curr = curr.prev;
|
|
346
|
+
}
|
|
347
|
+
const initialIndex = Math.min(flattened.length - 1, 1);
|
|
348
|
+
let name = "value";
|
|
349
|
+
for (let i = initialIndex + 1; i < flattened.length; ++i) {
|
|
350
|
+
name +=
|
|
351
|
+
flattened[i].type === "literal"
|
|
352
|
+
? `.${flattened[i].key}`
|
|
353
|
+
: `[$\{${flattened[i].key}}]`;
|
|
354
|
+
}
|
|
355
|
+
return name;
|
|
356
|
+
}
|
|
357
|
+
//# sourceMappingURL=variables.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"variables.js","sourceRoot":"","sources":["../../src/variables.ts"],"names":[],"mappings":";;;;;;;AAAA,+CAAsC;AACtC,qCAoBiB;AACjB,qCAAsE;AACtE,yCAA6D;AAC7D,2CAA+D;AAC/D,8DAAyC;AACzC,yCAKoB;AAEpB,MAAM,OAAO,GAAG,IAAA,oBAAa,GAAE,CAAC;AAYhC,8BAAqC,CAAM;IACzC,OAAO,CAAC,CAAC,MAAM,CAAC;AAClB,CAAC;AAgBD,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C","sourcesContent":["import { genFn } from \"./generate.js\";\nimport {\n GraphQLBoolean,\n GraphQLError,\n GraphQLFloat,\n GraphQLID,\n type GraphQLInputType,\n GraphQLInt,\n GraphQLSchema,\n GraphQLString,\n isEnumType,\n isInputType,\n isListType,\n isNonNullType,\n isScalarType,\n print,\n type OperationDefinitionNode,\n type SourceLocation,\n typeFromAST,\n valueFromAST,\n type VariableDefinitionNode\n} from \"graphql\";\nimport { addPath, computeLocations, type ObjectPath } from \"./ast.js\";\nimport { GraphQLError as GraphQLJITError } from \"./error.js\";\nimport { getDefaultValue, hasDefaultValue } from \"./compat.js\";\nimport createInspect from \"./inspect.js\";\nimport {\n appendSourceURL,\n createGeneratedSourceName,\n formatDebugSource,\n type CompilerDebugOptions\n} from \"./debug.js\";\n\nconst inspect = createInspect();\n\ninterface FailedVariableCoercion {\n errors: ReadonlyArray<GraphQLError>;\n}\n\ninterface VariableValues {\n coerced: { [key: string]: any };\n}\n\nexport type CoercedVariableValues = FailedVariableCoercion | VariableValues;\n\nexport function failToParseVariables(x: any): x is FailedVariableCoercion {\n return x.errors;\n}\n\ninterface CompilationContext {\n inputPath: ObjectPath;\n responsePath: ObjectPath;\n depth: number;\n varDefNode: VariableDefinitionNode;\n dependencies: Map<string, (...args: any[]) => any>;\n errorMessage?: string;\n}\n\ninterface VariableCompilationDebugOptions {\n compilerOptions: CompilerDebugOptions;\n operation: OperationDefinitionNode;\n}\n\nfunction createSubCompilationContext(\n context: CompilationContext\n): CompilationContext {\n return { ...context };\n}\nexport function compileVariableParsing(\n schema: GraphQLSchema,\n varDefNodes: ReadonlyArray<VariableDefinitionNode>,\n debug?: VariableCompilationDebugOptions\n): (inputs: { [key: string]: any }) => CoercedVariableValues {\n const errors = [];\n const coercedValues: { [key: string]: any } = Object.create(null);\n\n let mainBody = \"\";\n const dependencies = new Map();\n for (const varDefNode of varDefNodes) {\n const context: CompilationContext = {\n varDefNode,\n depth: 0,\n inputPath: addPath(undefined, \"input\"),\n responsePath: addPath(undefined, \"coerced\"),\n dependencies\n };\n const varName = varDefNode.variable.name.value;\n const varType = typeFromAST(schema, varDefNode.type as any);\n if (!varType || !isInputType(varType)) {\n // Must use input types for variables. This should be caught during\n // validation, however is checked again here for safety.\n errors.push(\n new (GraphQLJITError as any)(\n `Variable \"$${varName}\" expected value of type ` +\n `\"${\n varType || print(varDefNode.type)\n }\" which cannot be used as an input type.`,\n computeLocations([varDefNode.type])\n )\n );\n continue;\n }\n\n // Ensure a constant shape of the input map\n coercedValues[varName] = undefined;\n const hasValueName = hasValue(addPath(context.inputPath, varName));\n mainBody += `const ${hasValueName} = Object.prototype.hasOwnProperty.call(${getObjectPath(\n context.inputPath\n )}, \"${varName}\");\\n`;\n context.inputPath = addPath(context.inputPath, varName);\n context.responsePath = addPath(context.responsePath, varName);\n mainBody += generateInput(\n context,\n varType,\n varName,\n hasValueName,\n valueFromAST(varDefNode.defaultValue, varType),\n false\n );\n }\n\n if (errors.length > 0) {\n throw errors;\n }\n\n const gen = genFn();\n gen(`function getVariables(input) {\n const errors = [];\n const coerced = ${JSON.stringify(coercedValues)}\n ${mainBody}\n if (errors.length > 0) {\n return {errors, coerced: undefined};\n }\n return {errors: undefined, coerced};\n }\n `);\n\n const functionExpression = gen.toString();\n const functionBody = debug\n ? \"return \" +\n formatDebugSource(\n functionExpression,\n debug.compilerOptions.formatSourceCode\n )\n : `\n return ${functionExpression}`;\n const generatedSource = debug\n ? appendSourceURL(\n functionBody,\n createGeneratedSourceName(\n debug.operation.name?.value,\n debug.compilerOptions,\n \"variables\"\n )\n )\n : functionBody;\n\n // eslint-disable-next-line\n return Function.apply(\n null,\n [\"GraphQLJITError\", \"inspect\"]\n .concat(Array.from(dependencies.keys()))\n .concat(generatedSource)\n ).apply(\n null,\n [GraphQLJITError, inspect].concat(Array.from(dependencies.values()))\n );\n}\n\n// Int Scalars represent 32 bits\n// https://graphql.github.io/graphql-spec/June2018/#sec-Int\nconst MAX_32BIT_INT = 2147483647;\nconst MIN_32BIT_INT = -2147483648;\n\nfunction generateInput(\n context: CompilationContext,\n varType: GraphQLInputType,\n varName: string,\n hasValueName: string,\n defaultValue: unknown | undefined,\n wrapInList: boolean\n) {\n const currentOutput = getObjectPath(context.responsePath);\n const currentInput = getObjectPath(context.inputPath);\n const errorLocation = printErrorLocation(\n computeLocations([context.varDefNode])\n );\n\n const gen = genFn();\n gen(`if (${currentInput} == null) {`);\n\n if (isNonNullType(varType)) {\n let nonNullMessage;\n let omittedMessage;\n if (context.errorMessage) {\n const objectPath = printObjectPath(context.responsePath);\n nonNullMessage = `${context.errorMessage} + \\`Expected non-nullable type ${varType} not to be null at ${objectPath}.\\``;\n omittedMessage = `${context.errorMessage} + \\`Field ${objectPath} of required type ${varType} was not provided.\\``;\n } else {\n nonNullMessage = `'Variable \"$${varName}\" of non-null type \"${varType}\" must not be null.'`;\n omittedMessage = `'Variable \"$${varName}\" of required type \"${varType}\" was not provided.'`;\n }\n varType = varType.ofType;\n gen(`\n if (${currentOutput} == null) {\n errors.push(new GraphQLJITError(${hasValueName} ? ${nonNullMessage} : ${omittedMessage}, ${errorLocation}));\n }\n `);\n } else {\n gen(`\n if (${hasValueName}) { ${currentOutput} = null; }\n `);\n if (defaultValue !== undefined) {\n gen(`else { ${currentOutput} = ${JSON.stringify(defaultValue)} }`);\n }\n }\n gen(`} else {`);\n if (isScalarType(varType)) {\n switch (varType.name) {\n case GraphQLID.name:\n gen(`\n if (typeof ${currentInput} === \"string\") {\n ${currentOutput} = ${currentInput};\n } else if (Number.isInteger(${currentInput})) {\n ${currentOutput} = ${currentInput}.toString();\n } else {\n errors.push(new GraphQLJITError('Variable \"$${varName}\" got invalid value ' +\n inspect(${currentInput}) + \"; \" +\n 'Expected type ${varType.name}; ' +\n '${varType.name} cannot represent value: ' +\n inspect(${currentInput}), ${errorLocation})\n );\n }\n `);\n break;\n case GraphQLString.name:\n gen(`\n if (typeof ${currentInput} === \"string\") {\n ${currentOutput} = ${currentInput};\n } else {\n errors.push(new GraphQLJITError('Variable \"$${varName}\" got invalid value ' +\n inspect(${currentInput}) + \"; \" +\n 'Expected type ${varType.name}; ' +\n '${varType.name} cannot represent a non string value: ' +\n inspect(${currentInput}), ${errorLocation})\n );\n }\n `);\n break;\n case GraphQLBoolean.name:\n gen(`\n if (typeof ${currentInput} === \"boolean\") {\n ${currentOutput} = ${currentInput};\n } else {\n errors.push(new GraphQLJITError('Variable \"$${varName}\" got invalid value ' +\n inspect(${currentInput}) + \"; \" +\n 'Expected type ${varType.name}; ' +\n '${varType.name} cannot represent a non boolean value: ' +\n inspect(${currentInput}), ${errorLocation}));\n }\n `);\n break;\n case GraphQLInt.name:\n gen(`\n if (Number.isInteger(${currentInput})) {\n if (${currentInput} > ${MAX_32BIT_INT} || ${currentInput} < ${MIN_32BIT_INT}) {\n errors.push(new GraphQLJITError('Variable \"$${varName}\" got invalid value ' +\n inspect(${currentInput}) + \"; \" +\n 'Expected type ${varType.name}; ' +\n '${varType.name} cannot represent non 32-bit signed integer value: ' +\n inspect(${currentInput}), ${errorLocation}));\n } else {\n ${currentOutput} = ${currentInput};\n }\n } else {\n errors.push(new GraphQLJITError('Variable \"$${varName}\" got invalid value ' +\n inspect(${currentInput}) + \"; \" +\n 'Expected type ${varType.name}; ' +\n '${varType.name} cannot represent non-integer value: ' +\n inspect(${currentInput}), ${errorLocation})\n );\n }\n `);\n break;\n case GraphQLFloat.name:\n gen(`\n if (Number.isFinite(${currentInput})) {\n ${currentOutput} = ${currentInput};\n } else {\n errors.push(new GraphQLJITError('Variable \"$${varName}\" got invalid value ' +\n inspect(${currentInput}) + \"; \" +\n 'Expected type ${varType.name}; ' +\n '${varType.name} cannot represent non numeric value: ' +\n inspect(${currentInput}), ${errorLocation})\n );\n }\n `);\n break;\n default:\n context.dependencies.set(\n `${varType.name}parseValue`,\n varType.parseValue.bind(varType)\n );\n gen(`\n try {\n const parseResult = ${varType.name}parseValue(${currentInput});\n if (parseResult === undefined || parseResult !== parseResult) {\n errors.push(new GraphQLJITError('Variable \"$${varName}\" got invalid value ' +\n inspect(${currentInput}) + \"; \" +\n 'Expected type ${varType.name}.', ${errorLocation}));\n }\n ${currentOutput} = parseResult;\n } catch (error) {\n errors.push(new GraphQLJITError('Variable \"$${varName}\" got invalid value ' +\n inspect(${currentInput}) + \"; \" +\n 'Expected type ${varType.name}.', ${errorLocation}, undefined, error)\n );\n }\n `);\n }\n } else if (isEnumType(varType)) {\n context.dependencies.set(\n `${varType.name}getValue`,\n varType.getValue.bind(varType)\n );\n gen(`\n if (typeof ${currentInput} === \"string\") {\n const enumValue = ${varType.name}getValue(${currentInput});\n if (enumValue) {\n ${currentOutput} = enumValue.value;\n } else {\n errors.push(\n new GraphQLJITError('Variable \"$${varName}\" got invalid value ' +\n inspect(${currentInput}) + \"; \" +\n 'Expected type ${varType.name}.', ${errorLocation})\n );\n }\n } else {\n errors.push(\n new GraphQLJITError('Variable \"$${varName}\" got invalid value ' +\n inspect(${currentInput}) + \"; \" +\n 'Expected type ${varType.name}.', ${errorLocation})\n );\n }\n `);\n } else if (isListType(varType)) {\n context.errorMessage = `'Variable \"$${varName}\" got invalid value ' + inspect(${currentInput}) + '; '`;\n const hasValueName = hasValue(context.inputPath);\n const index = `idx${context.depth}`;\n\n const subContext = createSubCompilationContext(context);\n subContext.responsePath = addPath(\n subContext.responsePath,\n index,\n \"variable\"\n );\n subContext.inputPath = addPath(subContext.inputPath, index, \"variable\");\n subContext.depth++;\n gen(`\n if (Array.isArray(${currentInput})) {\n ${currentOutput} = [];\n for (let ${index} = 0; ${index} < ${currentInput}.length; ++${index}) {\n const ${hasValueName} =\n ${getObjectPath(subContext.inputPath)} !== undefined;\n ${generateInput(\n subContext,\n varType.ofType,\n varName,\n hasValueName,\n undefined,\n false\n )}\n }\n } else {\n ${generateInput(\n context,\n varType.ofType,\n varName,\n hasValueName,\n undefined,\n true\n )}\n }\n `);\n } else if (isInputType(varType)) {\n gen(`\n if (typeof ${currentInput} !== 'object') {\n errors.push(new GraphQLJITError('Variable \"$${varName}\" got invalid value ' +\n inspect(${currentInput}) + \"; \" +\n 'Expected type ${varType.name} to be an object.', ${errorLocation}));\n } else {\n ${currentOutput} = {};\n `);\n const fields = varType.getFields();\n const allowedFields = [];\n for (const field of Object.values(fields)) {\n const subContext = createSubCompilationContext(context);\n allowedFields.push(field.name);\n const hasValueName = hasValue(addPath(subContext.inputPath, field.name));\n gen(`\n const ${hasValueName} = Object.prototype.hasOwnProperty.call(\n ${getObjectPath(subContext.inputPath)}, \"${field.name}\"\n );\n `);\n subContext.inputPath = addPath(subContext.inputPath, field.name);\n subContext.responsePath = addPath(subContext.responsePath, field.name);\n subContext.errorMessage = `'Variable \"$${varName}\" got invalid value ' + inspect(${currentInput}) + '; '`;\n gen(`\n ${generateInput(\n subContext,\n field.type,\n field.name,\n hasValueName,\n hasDefaultValue(field) ? getDefaultValue(field) : undefined,\n false\n )}\n `);\n }\n\n gen(`\n const allowedFields = ${JSON.stringify(allowedFields)};\n for (const fieldName of Object.keys(${currentInput})) {\n if (!allowedFields.includes(fieldName)) {\n errors.push(new GraphQLJITError('Variable \"$${varName}\" got invalid value ' +\n inspect(${currentInput}) + \"; \" +\n 'Field \"' + fieldName + '\" is not defined by type ${\n varType.name\n }.', ${errorLocation}));\n break;\n }\n }\n }`);\n } else {\n /* istanbul ignore next line */\n throw new Error(`unknown type: ${varType}`);\n }\n if (wrapInList) {\n gen(`${currentOutput} = [${currentOutput}];`);\n }\n gen(`}`);\n return gen.toString();\n}\n\nfunction hasValue(path: ObjectPath) {\n const flattened = [];\n let curr: ObjectPath | undefined = path;\n while (curr) {\n flattened.push(curr.key);\n curr = curr.prev;\n }\n return `hasValue${flattened.join(\"_\")}`;\n}\n\nfunction printErrorLocation(location: SourceLocation[]) {\n return JSON.stringify(location);\n}\n\nfunction getObjectPath(path: ObjectPath): string {\n const flattened = [];\n let curr: ObjectPath | undefined = path;\n while (curr) {\n flattened.unshift({ key: curr.key, type: curr.type });\n curr = curr.prev;\n }\n let name = flattened[0].key;\n for (let i = 1; i < flattened.length; ++i) {\n name +=\n flattened[i].type === \"literal\"\n ? `[\"${flattened[i].key}\"]`\n : `[${flattened[i].key}]`;\n }\n return name;\n}\n\nfunction printObjectPath(path: ObjectPath) {\n const flattened = [];\n let curr: ObjectPath | undefined = path;\n while (curr) {\n flattened.unshift({ key: curr.key, type: curr.type });\n curr = curr.prev;\n }\n const initialIndex = Math.min(flattened.length - 1, 1);\n let name = \"value\";\n for (let i = initialIndex + 1; i < flattened.length; ++i) {\n name +=\n flattened[i].type === \"literal\"\n ? `.${flattened[i].key}`\n : `[$\\{${flattened[i].key}}]`;\n }\n return name;\n}\n"]}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { type ArgumentNode, type ASTNode, type DirectiveNode, type FieldNode, type GraphQLArgument, GraphQLDirective, type GraphQLField, type GraphQLInputType, GraphQLObjectType, type SelectionSetNode, type SourceLocation, type ValueNode, type VariableNode } from "graphql";
|
|
2
|
+
import { type CompilationContext } from "./execution.js";
|
|
3
|
+
import { resolveFieldDef } from "./compat.js";
|
|
4
|
+
export interface JitFieldNode extends FieldNode {
|
|
5
|
+
/**
|
|
6
|
+
* @deprecated Use __internalShouldIncludePath instead
|
|
7
|
+
* @see __internalShouldIncludePath
|
|
8
|
+
*/
|
|
9
|
+
__internalShouldInclude?: string[];
|
|
10
|
+
__internalShouldIncludePath?: {
|
|
11
|
+
[path: string]: string[];
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export interface FieldsAndNodes {
|
|
15
|
+
[key: string]: JitFieldNode[];
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Given a selectionSet, adds all of the fields in that selection to
|
|
19
|
+
* the passed in map of fields, and returns it at the end.
|
|
20
|
+
*
|
|
21
|
+
* CollectFields requires the "runtime type" of an object. For a field which
|
|
22
|
+
* returns an Interface or Union type, the "runtime type" will be the actual
|
|
23
|
+
* Object type returned by that field.
|
|
24
|
+
*/
|
|
25
|
+
export declare function collectFields(compilationContext: CompilationContext, runtimeType: GraphQLObjectType, selectionSet: SelectionSetNode, fields: FieldsAndNodes, visitedFragmentNames: {
|
|
26
|
+
[key: string]: boolean;
|
|
27
|
+
}, parentResponsePath?: ObjectPath): FieldsAndNodes;
|
|
28
|
+
export { resolveFieldDef };
|
|
29
|
+
export declare function collectSubfields(compilationContext: CompilationContext, returnType: GraphQLObjectType, fieldNodes: FieldNode[], parentResponsePath?: ObjectPath): {
|
|
30
|
+
[key: string]: FieldNode[];
|
|
31
|
+
};
|
|
32
|
+
type ResponsePathType = "variable" | "literal" | "meta";
|
|
33
|
+
export interface ObjectPath {
|
|
34
|
+
prev: ObjectPath | undefined;
|
|
35
|
+
key: string;
|
|
36
|
+
type: ResponsePathType;
|
|
37
|
+
}
|
|
38
|
+
interface MissingVariablePath {
|
|
39
|
+
valueNode: VariableNode;
|
|
40
|
+
path?: ObjectPath;
|
|
41
|
+
argument?: {
|
|
42
|
+
definition: GraphQLArgument;
|
|
43
|
+
node: ArgumentNode;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
export interface Arguments {
|
|
47
|
+
values: {
|
|
48
|
+
[argument: string]: any;
|
|
49
|
+
};
|
|
50
|
+
missing: MissingVariablePath[];
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Prepares an object map of argument values given a list of argument
|
|
54
|
+
* definitions and list of argument AST nodes.
|
|
55
|
+
*
|
|
56
|
+
* Note: The returned value is a plain Object with a prototype, since it is
|
|
57
|
+
* exposed to user code. Care should be taken to not pull values from the
|
|
58
|
+
* Object prototype.
|
|
59
|
+
*/
|
|
60
|
+
export declare function getArgumentDefs(def: GraphQLField<any, any> | GraphQLDirective, node: FieldNode | DirectiveNode): Arguments;
|
|
61
|
+
interface ASTValueWithVariables {
|
|
62
|
+
value: object | string | boolean | symbol | number | null | any[];
|
|
63
|
+
variables: MissingVariablePath[];
|
|
64
|
+
}
|
|
65
|
+
interface ASTValue {
|
|
66
|
+
value: object | string | boolean | symbol | number | null | any[];
|
|
67
|
+
}
|
|
68
|
+
export declare function valueFromAST(valueNode: ValueNode, type: GraphQLInputType): undefined | ASTValue | ASTValueWithVariables;
|
|
69
|
+
export declare function computeLocations(nodes: ASTNode[]): SourceLocation[];
|
|
70
|
+
export declare function addPath(responsePath: ObjectPath | undefined, key: string, type?: ResponsePathType): ObjectPath;
|
|
71
|
+
export declare function flattenPath(path: ObjectPath): Array<{
|
|
72
|
+
key: string;
|
|
73
|
+
type: ResponsePathType;
|
|
74
|
+
}>;
|
|
75
|
+
/**
|
|
76
|
+
* Serialize a path for use in the skip/include directives.
|
|
77
|
+
*
|
|
78
|
+
* @param path The path to serialize
|
|
79
|
+
* @returns The path serialized as a string, with the root path first.
|
|
80
|
+
*/
|
|
81
|
+
export declare function serializeObjectPathForSkipInclude(path: ObjectPath | undefined): string;
|
|
82
|
+
/**
|
|
83
|
+
* join two path segments to a dot notation, handling empty strings
|
|
84
|
+
*
|
|
85
|
+
* @param a path segment
|
|
86
|
+
* @param b path segment
|
|
87
|
+
* @returns combined path in dot notation
|
|
88
|
+
*/
|
|
89
|
+
export declare function joinSkipIncludePath(a: string, b: string): string;
|