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 @@
|
|
|
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,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,CAAC;YACN,SAAS,CAAC,IAAI,CAAC,CAAC;QAClB,CAAC;IACH,CAAC;IAED,cAAc,CAAC,GAAqB;QAClC,IAAI,GAAG,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,350 @@
|
|
|
1
|
+
import { genFn } from "./generate.js";
|
|
2
|
+
import { GraphQLBoolean, GraphQLFloat, GraphQLID, GraphQLInt, GraphQLString, isEnumType, isInputType, isListType, isNonNullType, isScalarType, print, typeFromAST, valueFromAST } from "graphql";
|
|
3
|
+
import { addPath, computeLocations } from "./ast.js";
|
|
4
|
+
import { GraphQLError as GraphQLJITError } from "./error.js";
|
|
5
|
+
import { getDefaultValue, hasDefaultValue } from "./compat.js";
|
|
6
|
+
import createInspect from "./inspect.js";
|
|
7
|
+
import { appendSourceURL, createGeneratedSourceName, formatDebugSource } from "./debug.js";
|
|
8
|
+
const inspect = createInspect();
|
|
9
|
+
export function failToParseVariables(x) {
|
|
10
|
+
return x.errors;
|
|
11
|
+
}
|
|
12
|
+
function createSubCompilationContext(context) {
|
|
13
|
+
return { ...context };
|
|
14
|
+
}
|
|
15
|
+
export function compileVariableParsing(schema, varDefNodes, debug) {
|
|
16
|
+
const errors = [];
|
|
17
|
+
const coercedValues = Object.create(null);
|
|
18
|
+
let mainBody = "";
|
|
19
|
+
const dependencies = new Map();
|
|
20
|
+
for (const varDefNode of varDefNodes) {
|
|
21
|
+
const context = {
|
|
22
|
+
varDefNode,
|
|
23
|
+
depth: 0,
|
|
24
|
+
inputPath: addPath(undefined, "input"),
|
|
25
|
+
responsePath: addPath(undefined, "coerced"),
|
|
26
|
+
dependencies
|
|
27
|
+
};
|
|
28
|
+
const varName = varDefNode.variable.name.value;
|
|
29
|
+
const varType = typeFromAST(schema, varDefNode.type);
|
|
30
|
+
if (!varType || !isInputType(varType)) {
|
|
31
|
+
// Must use input types for variables. This should be caught during
|
|
32
|
+
// validation, however is checked again here for safety.
|
|
33
|
+
errors.push(new GraphQLJITError(`Variable "$${varName}" expected value of type ` +
|
|
34
|
+
`"${varType || print(varDefNode.type)}" which cannot be used as an input type.`, computeLocations([varDefNode.type])));
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
// Ensure a constant shape of the input map
|
|
38
|
+
coercedValues[varName] = undefined;
|
|
39
|
+
const hasValueName = hasValue(addPath(context.inputPath, varName));
|
|
40
|
+
mainBody += `const ${hasValueName} = Object.prototype.hasOwnProperty.call(${getObjectPath(context.inputPath)}, "${varName}");\n`;
|
|
41
|
+
context.inputPath = addPath(context.inputPath, varName);
|
|
42
|
+
context.responsePath = addPath(context.responsePath, varName);
|
|
43
|
+
mainBody += generateInput(context, varType, varName, hasValueName, valueFromAST(varDefNode.defaultValue, varType), false);
|
|
44
|
+
}
|
|
45
|
+
if (errors.length > 0) {
|
|
46
|
+
throw errors;
|
|
47
|
+
}
|
|
48
|
+
const gen = genFn();
|
|
49
|
+
gen(`function getVariables(input) {
|
|
50
|
+
const errors = [];
|
|
51
|
+
const coerced = ${JSON.stringify(coercedValues)}
|
|
52
|
+
${mainBody}
|
|
53
|
+
if (errors.length > 0) {
|
|
54
|
+
return {errors, coerced: undefined};
|
|
55
|
+
}
|
|
56
|
+
return {errors: undefined, coerced};
|
|
57
|
+
}
|
|
58
|
+
`);
|
|
59
|
+
const functionExpression = gen.toString();
|
|
60
|
+
const functionBody = debug
|
|
61
|
+
? "return " +
|
|
62
|
+
formatDebugSource(functionExpression, debug.compilerOptions.formatSourceCode)
|
|
63
|
+
: `
|
|
64
|
+
return ${functionExpression}`;
|
|
65
|
+
const generatedSource = debug
|
|
66
|
+
? appendSourceURL(functionBody, createGeneratedSourceName(debug.operation.name?.value, debug.compilerOptions, "variables"))
|
|
67
|
+
: functionBody;
|
|
68
|
+
// eslint-disable-next-line
|
|
69
|
+
return Function.apply(null, ["GraphQLJITError", "inspect"]
|
|
70
|
+
.concat(Array.from(dependencies.keys()))
|
|
71
|
+
.concat(generatedSource)).apply(null, [GraphQLJITError, inspect].concat(Array.from(dependencies.values())));
|
|
72
|
+
}
|
|
73
|
+
// Int Scalars represent 32 bits
|
|
74
|
+
// https://graphql.github.io/graphql-spec/June2018/#sec-Int
|
|
75
|
+
const MAX_32BIT_INT = 2147483647;
|
|
76
|
+
const MIN_32BIT_INT = -2147483648;
|
|
77
|
+
function generateInput(context, varType, varName, hasValueName, defaultValue, wrapInList) {
|
|
78
|
+
const currentOutput = getObjectPath(context.responsePath);
|
|
79
|
+
const currentInput = getObjectPath(context.inputPath);
|
|
80
|
+
const errorLocation = printErrorLocation(computeLocations([context.varDefNode]));
|
|
81
|
+
const gen = genFn();
|
|
82
|
+
gen(`if (${currentInput} == null) {`);
|
|
83
|
+
if (isNonNullType(varType)) {
|
|
84
|
+
let nonNullMessage;
|
|
85
|
+
let omittedMessage;
|
|
86
|
+
if (context.errorMessage) {
|
|
87
|
+
const objectPath = printObjectPath(context.responsePath);
|
|
88
|
+
nonNullMessage = `${context.errorMessage} + \`Expected non-nullable type ${varType} not to be null at ${objectPath}.\``;
|
|
89
|
+
omittedMessage = `${context.errorMessage} + \`Field ${objectPath} of required type ${varType} was not provided.\``;
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
nonNullMessage = `'Variable "$${varName}" of non-null type "${varType}" must not be null.'`;
|
|
93
|
+
omittedMessage = `'Variable "$${varName}" of required type "${varType}" was not provided.'`;
|
|
94
|
+
}
|
|
95
|
+
varType = varType.ofType;
|
|
96
|
+
gen(`
|
|
97
|
+
if (${currentOutput} == null) {
|
|
98
|
+
errors.push(new GraphQLJITError(${hasValueName} ? ${nonNullMessage} : ${omittedMessage}, ${errorLocation}));
|
|
99
|
+
}
|
|
100
|
+
`);
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
gen(`
|
|
104
|
+
if (${hasValueName}) { ${currentOutput} = null; }
|
|
105
|
+
`);
|
|
106
|
+
if (defaultValue !== undefined) {
|
|
107
|
+
gen(`else { ${currentOutput} = ${JSON.stringify(defaultValue)} }`);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
gen(`} else {`);
|
|
111
|
+
if (isScalarType(varType)) {
|
|
112
|
+
switch (varType.name) {
|
|
113
|
+
case GraphQLID.name:
|
|
114
|
+
gen(`
|
|
115
|
+
if (typeof ${currentInput} === "string") {
|
|
116
|
+
${currentOutput} = ${currentInput};
|
|
117
|
+
} else if (Number.isInteger(${currentInput})) {
|
|
118
|
+
${currentOutput} = ${currentInput}.toString();
|
|
119
|
+
} else {
|
|
120
|
+
errors.push(new GraphQLJITError('Variable "$${varName}" got invalid value ' +
|
|
121
|
+
inspect(${currentInput}) + "; " +
|
|
122
|
+
'Expected type ${varType.name}; ' +
|
|
123
|
+
'${varType.name} cannot represent value: ' +
|
|
124
|
+
inspect(${currentInput}), ${errorLocation})
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
`);
|
|
128
|
+
break;
|
|
129
|
+
case GraphQLString.name:
|
|
130
|
+
gen(`
|
|
131
|
+
if (typeof ${currentInput} === "string") {
|
|
132
|
+
${currentOutput} = ${currentInput};
|
|
133
|
+
} else {
|
|
134
|
+
errors.push(new GraphQLJITError('Variable "$${varName}" got invalid value ' +
|
|
135
|
+
inspect(${currentInput}) + "; " +
|
|
136
|
+
'Expected type ${varType.name}; ' +
|
|
137
|
+
'${varType.name} cannot represent a non string value: ' +
|
|
138
|
+
inspect(${currentInput}), ${errorLocation})
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
`);
|
|
142
|
+
break;
|
|
143
|
+
case GraphQLBoolean.name:
|
|
144
|
+
gen(`
|
|
145
|
+
if (typeof ${currentInput} === "boolean") {
|
|
146
|
+
${currentOutput} = ${currentInput};
|
|
147
|
+
} else {
|
|
148
|
+
errors.push(new GraphQLJITError('Variable "$${varName}" got invalid value ' +
|
|
149
|
+
inspect(${currentInput}) + "; " +
|
|
150
|
+
'Expected type ${varType.name}; ' +
|
|
151
|
+
'${varType.name} cannot represent a non boolean value: ' +
|
|
152
|
+
inspect(${currentInput}), ${errorLocation}));
|
|
153
|
+
}
|
|
154
|
+
`);
|
|
155
|
+
break;
|
|
156
|
+
case GraphQLInt.name:
|
|
157
|
+
gen(`
|
|
158
|
+
if (Number.isInteger(${currentInput})) {
|
|
159
|
+
if (${currentInput} > ${MAX_32BIT_INT} || ${currentInput} < ${MIN_32BIT_INT}) {
|
|
160
|
+
errors.push(new GraphQLJITError('Variable "$${varName}" got invalid value ' +
|
|
161
|
+
inspect(${currentInput}) + "; " +
|
|
162
|
+
'Expected type ${varType.name}; ' +
|
|
163
|
+
'${varType.name} cannot represent non 32-bit signed integer value: ' +
|
|
164
|
+
inspect(${currentInput}), ${errorLocation}));
|
|
165
|
+
} else {
|
|
166
|
+
${currentOutput} = ${currentInput};
|
|
167
|
+
}
|
|
168
|
+
} else {
|
|
169
|
+
errors.push(new GraphQLJITError('Variable "$${varName}" got invalid value ' +
|
|
170
|
+
inspect(${currentInput}) + "; " +
|
|
171
|
+
'Expected type ${varType.name}; ' +
|
|
172
|
+
'${varType.name} cannot represent non-integer value: ' +
|
|
173
|
+
inspect(${currentInput}), ${errorLocation})
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
`);
|
|
177
|
+
break;
|
|
178
|
+
case GraphQLFloat.name:
|
|
179
|
+
gen(`
|
|
180
|
+
if (Number.isFinite(${currentInput})) {
|
|
181
|
+
${currentOutput} = ${currentInput};
|
|
182
|
+
} else {
|
|
183
|
+
errors.push(new GraphQLJITError('Variable "$${varName}" got invalid value ' +
|
|
184
|
+
inspect(${currentInput}) + "; " +
|
|
185
|
+
'Expected type ${varType.name}; ' +
|
|
186
|
+
'${varType.name} cannot represent non numeric value: ' +
|
|
187
|
+
inspect(${currentInput}), ${errorLocation})
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
`);
|
|
191
|
+
break;
|
|
192
|
+
default:
|
|
193
|
+
context.dependencies.set(`${varType.name}parseValue`, varType.parseValue.bind(varType));
|
|
194
|
+
gen(`
|
|
195
|
+
try {
|
|
196
|
+
const parseResult = ${varType.name}parseValue(${currentInput});
|
|
197
|
+
if (parseResult === undefined || parseResult !== parseResult) {
|
|
198
|
+
errors.push(new GraphQLJITError('Variable "$${varName}" got invalid value ' +
|
|
199
|
+
inspect(${currentInput}) + "; " +
|
|
200
|
+
'Expected type ${varType.name}.', ${errorLocation}));
|
|
201
|
+
}
|
|
202
|
+
${currentOutput} = parseResult;
|
|
203
|
+
} catch (error) {
|
|
204
|
+
errors.push(new GraphQLJITError('Variable "$${varName}" got invalid value ' +
|
|
205
|
+
inspect(${currentInput}) + "; " +
|
|
206
|
+
'Expected type ${varType.name}.', ${errorLocation}, undefined, error)
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
`);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
else if (isEnumType(varType)) {
|
|
213
|
+
context.dependencies.set(`${varType.name}getValue`, varType.getValue.bind(varType));
|
|
214
|
+
gen(`
|
|
215
|
+
if (typeof ${currentInput} === "string") {
|
|
216
|
+
const enumValue = ${varType.name}getValue(${currentInput});
|
|
217
|
+
if (enumValue) {
|
|
218
|
+
${currentOutput} = enumValue.value;
|
|
219
|
+
} else {
|
|
220
|
+
errors.push(
|
|
221
|
+
new GraphQLJITError('Variable "$${varName}" got invalid value ' +
|
|
222
|
+
inspect(${currentInput}) + "; " +
|
|
223
|
+
'Expected type ${varType.name}.', ${errorLocation})
|
|
224
|
+
);
|
|
225
|
+
}
|
|
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
|
+
`);
|
|
234
|
+
}
|
|
235
|
+
else if (isListType(varType)) {
|
|
236
|
+
context.errorMessage = `'Variable "$${varName}" got invalid value ' + inspect(${currentInput}) + '; '`;
|
|
237
|
+
const hasValueName = hasValue(context.inputPath);
|
|
238
|
+
const index = `idx${context.depth}`;
|
|
239
|
+
const subContext = createSubCompilationContext(context);
|
|
240
|
+
subContext.responsePath = addPath(subContext.responsePath, index, "variable");
|
|
241
|
+
subContext.inputPath = addPath(subContext.inputPath, index, "variable");
|
|
242
|
+
subContext.depth++;
|
|
243
|
+
gen(`
|
|
244
|
+
if (Array.isArray(${currentInput})) {
|
|
245
|
+
${currentOutput} = [];
|
|
246
|
+
for (let ${index} = 0; ${index} < ${currentInput}.length; ++${index}) {
|
|
247
|
+
const ${hasValueName} =
|
|
248
|
+
${getObjectPath(subContext.inputPath)} !== undefined;
|
|
249
|
+
${generateInput(subContext, varType.ofType, varName, hasValueName, undefined, false)}
|
|
250
|
+
}
|
|
251
|
+
} else {
|
|
252
|
+
${generateInput(context, varType.ofType, varName, hasValueName, undefined, true)}
|
|
253
|
+
}
|
|
254
|
+
`);
|
|
255
|
+
}
|
|
256
|
+
else if (isInputType(varType)) {
|
|
257
|
+
gen(`
|
|
258
|
+
if (typeof ${currentInput} !== 'object') {
|
|
259
|
+
errors.push(new GraphQLJITError('Variable "$${varName}" got invalid value ' +
|
|
260
|
+
inspect(${currentInput}) + "; " +
|
|
261
|
+
'Expected type ${varType.name} to be an object.', ${errorLocation}));
|
|
262
|
+
} else {
|
|
263
|
+
${currentOutput} = {};
|
|
264
|
+
`);
|
|
265
|
+
const fields = varType.getFields();
|
|
266
|
+
const allowedFields = [];
|
|
267
|
+
for (const field of Object.values(fields)) {
|
|
268
|
+
const subContext = createSubCompilationContext(context);
|
|
269
|
+
allowedFields.push(field.name);
|
|
270
|
+
const hasValueName = hasValue(addPath(subContext.inputPath, field.name));
|
|
271
|
+
gen(`
|
|
272
|
+
const ${hasValueName} = Object.prototype.hasOwnProperty.call(
|
|
273
|
+
${getObjectPath(subContext.inputPath)}, "${field.name}"
|
|
274
|
+
);
|
|
275
|
+
`);
|
|
276
|
+
subContext.inputPath = addPath(subContext.inputPath, field.name);
|
|
277
|
+
subContext.responsePath = addPath(subContext.responsePath, field.name);
|
|
278
|
+
subContext.errorMessage = `'Variable "$${varName}" got invalid value ' + inspect(${currentInput}) + '; '`;
|
|
279
|
+
gen(`
|
|
280
|
+
${generateInput(subContext, field.type, field.name, hasValueName, hasDefaultValue(field) ? getDefaultValue(field) : undefined, false)}
|
|
281
|
+
`);
|
|
282
|
+
}
|
|
283
|
+
gen(`
|
|
284
|
+
const allowedFields = ${JSON.stringify(allowedFields)};
|
|
285
|
+
for (const fieldName of Object.keys(${currentInput})) {
|
|
286
|
+
if (!allowedFields.includes(fieldName)) {
|
|
287
|
+
errors.push(new GraphQLJITError('Variable "$${varName}" got invalid value ' +
|
|
288
|
+
inspect(${currentInput}) + "; " +
|
|
289
|
+
'Field "' + fieldName + '" is not defined by type ${varType.name}.', ${errorLocation}));
|
|
290
|
+
break;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}`);
|
|
294
|
+
}
|
|
295
|
+
else {
|
|
296
|
+
/* istanbul ignore next line */
|
|
297
|
+
throw new Error(`unknown type: ${varType}`);
|
|
298
|
+
}
|
|
299
|
+
if (wrapInList) {
|
|
300
|
+
gen(`${currentOutput} = [${currentOutput}];`);
|
|
301
|
+
}
|
|
302
|
+
gen(`}`);
|
|
303
|
+
return gen.toString();
|
|
304
|
+
}
|
|
305
|
+
function hasValue(path) {
|
|
306
|
+
const flattened = [];
|
|
307
|
+
let curr = path;
|
|
308
|
+
while (curr) {
|
|
309
|
+
flattened.push(curr.key);
|
|
310
|
+
curr = curr.prev;
|
|
311
|
+
}
|
|
312
|
+
return `hasValue${flattened.join("_")}`;
|
|
313
|
+
}
|
|
314
|
+
function printErrorLocation(location) {
|
|
315
|
+
return JSON.stringify(location);
|
|
316
|
+
}
|
|
317
|
+
function getObjectPath(path) {
|
|
318
|
+
const flattened = [];
|
|
319
|
+
let curr = path;
|
|
320
|
+
while (curr) {
|
|
321
|
+
flattened.unshift({ key: curr.key, type: curr.type });
|
|
322
|
+
curr = curr.prev;
|
|
323
|
+
}
|
|
324
|
+
let name = flattened[0].key;
|
|
325
|
+
for (let i = 1; i < flattened.length; ++i) {
|
|
326
|
+
name +=
|
|
327
|
+
flattened[i].type === "literal"
|
|
328
|
+
? `["${flattened[i].key}"]`
|
|
329
|
+
: `[${flattened[i].key}]`;
|
|
330
|
+
}
|
|
331
|
+
return name;
|
|
332
|
+
}
|
|
333
|
+
function printObjectPath(path) {
|
|
334
|
+
const flattened = [];
|
|
335
|
+
let curr = path;
|
|
336
|
+
while (curr) {
|
|
337
|
+
flattened.unshift({ key: curr.key, type: curr.type });
|
|
338
|
+
curr = curr.prev;
|
|
339
|
+
}
|
|
340
|
+
const initialIndex = Math.min(flattened.length - 1, 1);
|
|
341
|
+
let name = "value";
|
|
342
|
+
for (let i = initialIndex + 1; i < flattened.length; ++i) {
|
|
343
|
+
name +=
|
|
344
|
+
flattened[i].type === "literal"
|
|
345
|
+
? `.${flattened[i].key}`
|
|
346
|
+
: `[$\{${flattened[i].key}}]`;
|
|
347
|
+
}
|
|
348
|
+
return name;
|
|
349
|
+
}
|
|
350
|
+
//# sourceMappingURL=variables.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"variables.js","sourceRoot":"","sources":["../../src/variables.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EACL,cAAc,EAEd,YAAY,EACZ,SAAS,EAET,UAAU,EAEV,aAAa,EACb,UAAU,EACV,WAAW,EACX,UAAU,EACV,aAAa,EACb,YAAY,EACZ,KAAK,EAGL,WAAW,EACX,YAAY,EAEb,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAmB,MAAM,UAAU,CAAC;AACtE,OAAO,EAAE,YAAY,IAAI,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC/D,OAAO,aAAa,MAAM,cAAc,CAAC;AACzC,OAAO,EACL,eAAe,EACf,yBAAyB,EACzB,iBAAiB,EAElB,MAAM,YAAY,CAAC;AAEpB,MAAM,OAAO,GAAG,aAAa,EAAE,CAAC;AAYhC,MAAM,UAAU,oBAAoB,CAAC,CAAM;IACzC,OAAO,CAAC,CAAC,MAAM,CAAC;AAClB,C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C,IAAI;YACF,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,SAAS;gBAC7B,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI;gBAC3B,CAAC,CAAC,IAAI,SAAS,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;IAChC,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAS,eAAe,CAAC,IAAgB;IACvC,MAAM,SAAS,GAAG,EAAE,CAAC;IACrB,IAAI,IAAI,GAA2B,IAAI,CAAC;IACxC,OAAO,IAAI,EAAE,CAAC;QACZ,SAAS,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;QACtD,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IACD,MAAM,YAAY,GAAG,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;IACvD,IAAI,IAAI,GAAG,OAAO,CAAC;IACnB,KAAK,IAAI,CAAC,GAAG,YAAY,GAAG,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE,CAAC;QACzD,IAAI;YACF,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,SAAS;gBAC7B,CAAC,CAAC,IAAI,SAAS,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE;gBACxB,CAAC,CAAC,OAAO,SAAS,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IACpC,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC","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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "graphql-jit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "GraphQL JIT Compiler to JS",
|
|
5
5
|
"author": "Rui Araujo",
|
|
6
6
|
"license": "MIT",
|
|
@@ -8,36 +8,39 @@
|
|
|
8
8
|
"type": "git",
|
|
9
9
|
"url": "https://github.com/zalando-incubator/graphql-jit.git"
|
|
10
10
|
},
|
|
11
|
-
"main": "dist/index.js",
|
|
12
|
-
"module": "dist/index.
|
|
11
|
+
"main": "dist/cjs/index.js",
|
|
12
|
+
"module": "dist/esm/index.js",
|
|
13
|
+
"types": "dist/cjs/index.d.ts",
|
|
13
14
|
"exports": {
|
|
14
|
-
"./package.json": "./package.json",
|
|
15
15
|
".": {
|
|
16
|
-
"
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
"import":
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
"import": "./dist/*.mjs",
|
|
25
|
-
"require": "./dist/*.js"
|
|
16
|
+
"require": {
|
|
17
|
+
"types": "./dist/cjs/index.d.ts",
|
|
18
|
+
"default": "./dist/cjs/index.js"
|
|
19
|
+
},
|
|
20
|
+
"import": {
|
|
21
|
+
"types": "./dist/esm/index.d.ts",
|
|
22
|
+
"default": "./dist/esm/index.js"
|
|
23
|
+
}
|
|
26
24
|
},
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
|
|
25
|
+
"./*": {
|
|
26
|
+
"require": {
|
|
27
|
+
"types": "./dist/cjs/*.d.ts",
|
|
28
|
+
"default": "./dist/cjs/*.js"
|
|
29
|
+
},
|
|
30
|
+
"import": {
|
|
31
|
+
"types": "./dist/esm/*.d.ts",
|
|
32
|
+
"default": "./dist/esm/*.js"
|
|
33
|
+
}
|
|
30
34
|
},
|
|
31
|
-
"./
|
|
32
|
-
"import": "./dist/*.mjs",
|
|
33
|
-
"require": "./dist/*.js"
|
|
34
|
-
}
|
|
35
|
+
"./package.json": "./package.json"
|
|
35
36
|
},
|
|
36
37
|
"scripts": {
|
|
37
38
|
"benchmark": "NODE_ENV=production node --loader @swc-node/register/esm src/__benchmarks__/benchmarks.ts",
|
|
38
|
-
"build": "yarn
|
|
39
|
-
"
|
|
40
|
-
"
|
|
39
|
+
"build": "node scripts/prepare-build.js && yarn build:cjs && yarn build:esm",
|
|
40
|
+
"build:cjs": "tsc --project tsconfig.cjs.json",
|
|
41
|
+
"build:esm": "tsc --project tsconfig.esm.json",
|
|
42
|
+
"check-exports": "node scripts/check-exports.js",
|
|
43
|
+
"check-tsc": "tsc --noEmit --project tsconfig.json",
|
|
41
44
|
"codecov": "codecov",
|
|
42
45
|
"format": "prettier --write 'src/**/*.ts'",
|
|
43
46
|
"lint-fix": "yarn lint --fix",
|
|
@@ -48,7 +51,7 @@
|
|
|
48
51
|
"test": "jest"
|
|
49
52
|
},
|
|
50
53
|
"files": [
|
|
51
|
-
"dist
|
|
54
|
+
"dist"
|
|
52
55
|
],
|
|
53
56
|
"jest": {
|
|
54
57
|
"extensionsToTreatAsEsm": [
|
|
@@ -82,9 +85,10 @@
|
|
|
82
85
|
"graphql": ">=15"
|
|
83
86
|
},
|
|
84
87
|
"devDependencies": {
|
|
85
|
-
"@arethetypeswrong/cli": "^0.
|
|
86
|
-
"@eslint/js": "^
|
|
88
|
+
"@arethetypeswrong/cli": "^0.18.5",
|
|
89
|
+
"@eslint/js": "^10.0.1",
|
|
87
90
|
"@graphql-tools/schema": "^10.0.0",
|
|
91
|
+
"@prettier/sync": "^0.6.1",
|
|
88
92
|
"@stryker-mutator/core": "^7.1.1",
|
|
89
93
|
"@stryker-mutator/jest-runner": "^7.1.1",
|
|
90
94
|
"@stryker-mutator/typescript": "^4.0.0",
|
|
@@ -97,21 +101,21 @@
|
|
|
97
101
|
"@types/lodash.memoize": "^4.1.7",
|
|
98
102
|
"@types/lodash.merge": "^4.6.7",
|
|
99
103
|
"@types/lodash.mergewith": "^4.6.7",
|
|
100
|
-
"@types/node": "^
|
|
104
|
+
"@types/node": "^22.0.0",
|
|
105
|
+
"@typescript/native": "npm:typescript@^7.0.2",
|
|
101
106
|
"benchmark": "^2.1.4",
|
|
102
107
|
"codecov": "^3.8.2",
|
|
103
108
|
"compare-versions": "^6.1.1",
|
|
104
|
-
"eslint": "^
|
|
105
|
-
"eslint-config-prettier": "^
|
|
106
|
-
"eslint-plugin-prettier": "^5.
|
|
109
|
+
"eslint": "^10.11.0",
|
|
110
|
+
"eslint-config-prettier": "^10.1.8",
|
|
111
|
+
"eslint-plugin-prettier": "^5.5.6",
|
|
107
112
|
"globals": "^15.9.0",
|
|
108
113
|
"graphql": "^17.0.1",
|
|
109
114
|
"jest": "^29.7.0",
|
|
110
115
|
"lint-staged": "^14.0.1",
|
|
111
116
|
"prettier": "^3.0.3",
|
|
112
|
-
"
|
|
113
|
-
"typescript": "^
|
|
114
|
-
"typescript-eslint": "^8.5.0"
|
|
117
|
+
"typescript": "npm:@typescript/typescript6@^6.0.2",
|
|
118
|
+
"typescript-eslint": "^8.70.1"
|
|
115
119
|
},
|
|
116
120
|
"dependencies": {
|
|
117
121
|
"@graphql-typed-document-node/core": "^3.2.0",
|
|
@@ -134,5 +138,5 @@
|
|
|
134
138
|
]
|
|
135
139
|
}
|
|
136
140
|
},
|
|
137
|
-
"packageManager": "yarn@4.
|
|
141
|
+
"packageManager": "yarn@4.18.0"
|
|
138
142
|
}
|
package/dist/ast.d.mts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import 'graphql';
|
|
2
|
-
export { A as Arguments, F as FieldsAndNodes, t as JitFieldNode, O as ObjectPath, z as addPath, u as collectFields, v as collectSubfields, y as computeLocations, B as flattenPath, w as getArgumentDefs, H as joinSkipIncludePath, r as resolveFieldDef, D as serializeObjectPathForSkipInclude, x as valueFromAST } from './index-CeluTkd4.mjs';
|
|
3
|
-
import '@graphql-typed-document-node/core';
|
|
4
|
-
import './types.mjs';
|
|
5
|
-
import './error.mjs';
|
|
6
|
-
import './resolve-info.mjs';
|
|
7
|
-
import './variables.mjs';
|
package/dist/ast.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import 'graphql';
|
|
2
|
-
export { A as Arguments, F as FieldsAndNodes, t as JitFieldNode, O as ObjectPath, z as addPath, u as collectFields, v as collectSubfields, y as computeLocations, B as flattenPath, w as getArgumentDefs, H as joinSkipIncludePath, r as resolveFieldDef, D as serializeObjectPathForSkipInclude, x as valueFromAST } from './index-mKv2zpdA.js';
|
|
3
|
-
import '@graphql-typed-document-node/core';
|
|
4
|
-
import './types.js';
|
|
5
|
-
import './error.js';
|
|
6
|
-
import './resolve-info.js';
|
|
7
|
-
import './variables.js';
|