graphql-jit 0.9.3 → 0.9.4
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/dist/cjs/ast.d.ts +3 -0
- package/dist/cjs/ast.js +8 -2
- package/dist/cjs/ast.js.map +1 -1
- package/dist/cjs/compat.d.ts +3 -3
- package/dist/cjs/compat.js +12 -8
- package/dist/cjs/compat.js.map +1 -1
- package/dist/cjs/compile-input.d.ts +10 -0
- package/dist/cjs/compile-input.js +63 -0
- package/dist/cjs/compile-input.js.map +1 -0
- package/dist/cjs/execution.d.ts +3 -0
- package/dist/cjs/execution.js +24 -74
- package/dist/cjs/execution.js.map +1 -1
- package/dist/cjs/non-null.d.ts +5 -0
- package/dist/cjs/non-null.js +9 -0
- package/dist/cjs/non-null.js.map +1 -1
- package/dist/cjs/variables.js +36 -6
- package/dist/cjs/variables.js.map +1 -1
- package/dist/esm/ast.d.ts +3 -0
- package/dist/esm/ast.js +8 -2
- package/dist/esm/ast.js.map +1 -1
- package/dist/esm/compat.d.ts +3 -3
- package/dist/esm/compat.js +12 -8
- package/dist/esm/compat.js.map +1 -1
- package/dist/esm/compile-input.d.ts +10 -0
- package/dist/esm/compile-input.js +60 -0
- package/dist/esm/compile-input.js.map +1 -0
- package/dist/esm/execution.d.ts +3 -0
- package/dist/esm/execution.js +25 -75
- package/dist/esm/execution.js.map +1 -1
- package/dist/esm/non-null.d.ts +5 -0
- package/dist/esm/non-null.js +8 -0
- package/dist/esm/non-null.js.map +1 -1
- package/dist/esm/variables.js +36 -6
- package/dist/esm/variables.js.map +1 -1
- package/package.json +1 -1
package/dist/esm/variables.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { genFn } from "./generate.js";
|
|
2
2
|
import { GraphQLBoolean, GraphQLFloat, GraphQLID, GraphQLInt, GraphQLString, isEnumType, isInputType, isListType, isNonNullType, isScalarType, print, typeFromAST, valueFromAST } from "graphql";
|
|
3
3
|
import { addPath, computeLocations } from "./ast.js";
|
|
4
|
+
import { compileInputValue } from "./compile-input.js";
|
|
4
5
|
import { GraphQLError as GraphQLJITError } from "./error.js";
|
|
5
6
|
import { coerceInputValue, getDefaultValue, hasDefaultValue } from "./compat.js";
|
|
6
7
|
import createInspect from "./inspect.js";
|
|
@@ -74,7 +75,21 @@ export function compileVariableParsing(schema, varDefNodes, debug) {
|
|
|
74
75
|
// https://graphql.github.io/graphql-spec/June2018/#sec-Int
|
|
75
76
|
const MAX_32BIT_INT = 2147483647;
|
|
76
77
|
const MIN_32BIT_INT = -2147483648;
|
|
78
|
+
/**
|
|
79
|
+
* Default values are internal values, so a custom scalar may use bigints,
|
|
80
|
+
* dates or other values that cannot be written into source. Containers are
|
|
81
|
+
* emitted inline, so every execution gets fresh ones, and opaque values are
|
|
82
|
+
* bound as compiler dependencies.
|
|
83
|
+
*/
|
|
84
|
+
function compileDefault(context, type, defaultValue) {
|
|
85
|
+
return compileInputValue(defaultValue, type, (value) => {
|
|
86
|
+
const name = `__default${context.dependencies.size}`;
|
|
87
|
+
context.dependencies.set(name, value);
|
|
88
|
+
return name;
|
|
89
|
+
});
|
|
90
|
+
}
|
|
77
91
|
function generateInput(context, varType, varName, hasValueName, defaultValue, wrapInList) {
|
|
92
|
+
const declaredType = varType;
|
|
78
93
|
const currentOutput = getObjectPath(context.responsePath);
|
|
79
94
|
const currentInput = getObjectPath(context.inputPath);
|
|
80
95
|
const errorLocation = printErrorLocation(computeLocations([context.varDefNode]));
|
|
@@ -93,18 +108,33 @@ function generateInput(context, varType, varName, hasValueName, defaultValue, wr
|
|
|
93
108
|
omittedMessage = `'Variable "$${varName}" of required type "${varType}" was not provided.'`;
|
|
94
109
|
}
|
|
95
110
|
varType = varType.ofType;
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
111
|
+
if (defaultValue !== undefined) {
|
|
112
|
+
// A non-null input with a default is not required; only an explicit
|
|
113
|
+
// null is an error.
|
|
114
|
+
gen(`
|
|
115
|
+
if (${currentOutput} == null) {
|
|
116
|
+
if (${hasValueName}) {
|
|
117
|
+
errors.push(new GraphQLJITError(${nonNullMessage}, ${errorLocation}));
|
|
118
|
+
} else {
|
|
119
|
+
${currentOutput} = ${compileDefault(context, declaredType, defaultValue)};
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
`);
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
gen(`
|
|
126
|
+
if (${currentOutput} == null) {
|
|
127
|
+
errors.push(new GraphQLJITError(${hasValueName} ? ${nonNullMessage} : ${omittedMessage}, ${errorLocation}));
|
|
128
|
+
}
|
|
129
|
+
`);
|
|
130
|
+
}
|
|
101
131
|
}
|
|
102
132
|
else {
|
|
103
133
|
gen(`
|
|
104
134
|
if (${hasValueName}) { ${currentOutput} = null; }
|
|
105
135
|
`);
|
|
106
136
|
if (defaultValue !== undefined) {
|
|
107
|
-
gen(`else { ${currentOutput} = ${
|
|
137
|
+
gen(`else { ${currentOutput} = ${compileDefault(context, declaredType, defaultValue)}; }`);
|
|
108
138
|
}
|
|
109
139
|
}
|
|
110
140
|
gen(`} else {`);
|
|
@@ -1 +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,EACL,gBAAgB,EAChB,eAAe,EACf,eAAe,EAChB,MAAM,aAAa,CAA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S,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 {\n coerceInputValue,\n getDefaultValue,\n hasDefaultValue\n} 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 (value: unknown) => coerceInputValue(varType, value)\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"]}
|
|
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,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,YAAY,IAAI,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7D,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,eAAe,EAChB,MAAM,aAAa,CAAC;AACrB,OAAO,aAAa,MAAM,cAAc,CAAC;AACzC,OAAO,EACL,eAAe,EACf,yBAAyB,EACzB,iBAAiB,EAElB,MAAM,YAAY,CAAC;AAEpB,MAAM,OAAO,GAAG,aAAa,EAAE,CAAC;AAY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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 { compileInputValue } from \"./compile-input.js\";\nimport { GraphQLError as GraphQLJITError } from \"./error.js\";\nimport {\n coerceInputValue,\n getDefaultValue,\n hasDefaultValue\n} 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, unknown>;\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\n/**\n * Default values are internal values, so a custom scalar may use bigints,\n * dates or other values that cannot be written into source. Containers are\n * emitted inline, so every execution gets fresh ones, and opaque values are\n * bound as compiler dependencies.\n */\nfunction compileDefault(\n context: CompilationContext,\n type: GraphQLInputType,\n defaultValue: unknown\n): string {\n return compileInputValue(defaultValue, type, (value) => {\n const name = `__default${context.dependencies.size}`;\n context.dependencies.set(name, value);\n return name;\n });\n}\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 declaredType = varType;\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 if (defaultValue !== undefined) {\n // A non-null input with a default is not required; only an explicit\n // null is an error.\n gen(`\n if (${currentOutput} == null) {\n if (${hasValueName}) {\n errors.push(new GraphQLJITError(${nonNullMessage}, ${errorLocation}));\n } else {\n ${currentOutput} = ${compileDefault(\n context,\n declaredType,\n defaultValue\n )};\n }\n }\n `);\n } else {\n gen(`\n if (${currentOutput} == null) {\n errors.push(new GraphQLJITError(${hasValueName} ? ${nonNullMessage} : ${omittedMessage}, ${errorLocation}));\n }\n `);\n }\n } else {\n gen(`\n if (${hasValueName}) { ${currentOutput} = null; }\n `);\n if (defaultValue !== undefined) {\n gen(\n `else { ${currentOutput} = ${compileDefault(\n context,\n declaredType,\n defaultValue\n )}; }`\n );\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 (value: unknown) => coerceInputValue(varType, value)\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"]}
|