graphql-jit 0.8.8 → 0.8.9
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/ast.d.mts +1 -2
- package/dist/ast.d.ts +1 -2
- package/dist/ast.js +65 -65
- package/dist/ast.js.map +1 -1
- package/dist/ast.mjs +67 -65
- package/dist/ast.mjs.map +1 -1
- package/dist/compat.d.mts +1 -2
- package/dist/compat.d.ts +1 -2
- package/dist/compat.js +13 -0
- package/dist/compat.js.map +1 -1
- package/dist/compat.mjs +11 -0
- package/dist/compat.mjs.map +1 -1
- package/dist/execution.d.mts +1 -2
- package/dist/execution.d.ts +1 -2
- package/dist/execution.js +4 -6
- package/dist/execution.js.map +1 -1
- package/dist/execution.mjs +1 -3
- package/dist/execution.mjs.map +1 -1
- package/dist/{index-Bjv1gl9X.d.mts → index-CeluTkd4.d.mts} +74 -47
- package/dist/{index-qBTBoZdC.d.ts → index-mKv2zpdA.d.ts} +74 -47
- package/dist/index.d.mts +1 -2
- package/dist/index.d.ts +1 -2
- package/dist/json.d.mts +1 -2
- package/dist/json.d.ts +1 -2
- package/dist/non-null.d.mts +1 -2
- package/dist/non-null.d.ts +1 -2
- package/dist/runtime.d.mts +1 -2
- package/dist/runtime.d.ts +1 -2
- package/dist/variables.js +2 -1
- package/dist/variables.js.map +1 -1
- package/dist/variables.mjs +2 -1
- package/dist/variables.mjs.map +1 -1
- package/package.json +3 -3
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { TypedDocumentNode } from '@graphql-typed-document-node/core';
|
|
2
|
-
import {
|
|
3
|
-
import { ExecutionContext as ExecutionContext$1 } from 'graphql/execution/execute.js';
|
|
2
|
+
import { GraphQLSchema, OperationDefinitionNode, GraphQLObjectType, GraphQLError, GraphQLFormattedError, ASTNode, FieldNode, GraphQLField, GraphQLScalarType, ConstValueNode, GraphQLFieldResolver, GraphQLTypeResolver, GraphQLIsTypeOfFn, FragmentDefinitionNode, ExecutionResult, DocumentNode, GraphQLOutputType, SelectionSetNode, GraphQLDirective, DirectiveNode, ValueNode, GraphQLInputType, SourceLocation, VariableNode, GraphQLArgument, ArgumentNode } from 'graphql';
|
|
4
3
|
import { Maybe } from './types.js';
|
|
5
4
|
import { GraphQLError as GraphQLError$1 } from './error.js';
|
|
6
5
|
import { ResolveInfoEnricherInput } from './resolve-info.js';
|
|
@@ -19,6 +18,78 @@ declare const jitRuntime: {
|
|
|
19
18
|
};
|
|
20
19
|
type JitRuntime = typeof jitRuntime;
|
|
21
20
|
|
|
21
|
+
/**
|
|
22
|
+
* A helper file to support backward compatibility for different versions of graphql-js.
|
|
23
|
+
*/
|
|
24
|
+
/**
|
|
25
|
+
* v15 does not have schema.getRootType
|
|
26
|
+
* v16 has both
|
|
27
|
+
* v17 will not have getOperationRootType
|
|
28
|
+
*
|
|
29
|
+
* To support all these 3 versions of graphql-js, at least for migration, this helper
|
|
30
|
+
* would be useful.
|
|
31
|
+
*
|
|
32
|
+
* This can be removed once we drop support for v15.
|
|
33
|
+
*
|
|
34
|
+
* GraphQL v17 would remove getOperationRootType.
|
|
35
|
+
*/
|
|
36
|
+
declare function getOperationRootType(schema: GraphQLSchema, operation: OperationDefinitionNode): GraphQLObjectType;
|
|
37
|
+
/**
|
|
38
|
+
* v16 and lower versions don't have .toJSON method on GraphQLError
|
|
39
|
+
* v17 does have .toJSON and doesn't have "formatError" export anymore
|
|
40
|
+
*/
|
|
41
|
+
declare function formatError(error: GraphQLError): GraphQLFormattedError;
|
|
42
|
+
/**
|
|
43
|
+
* v17 dropped support for positional arguments in GraphQLError constructor
|
|
44
|
+
* https://github.com/graphql/graphql-js/pull/3577
|
|
45
|
+
*/
|
|
46
|
+
declare function getGraphQLErrorOptions(nodes: Maybe<ReadonlyArray<ASTNode> | ASTNode>): ConstructorParameters<typeof GraphQLError>[1];
|
|
47
|
+
/**
|
|
48
|
+
* Resolves the field on the given source object. In particular, this
|
|
49
|
+
* figures out the value that the field returns by calling its resolve function,
|
|
50
|
+
* then calls completeValue to complete promises, serialize scalars, or execute
|
|
51
|
+
* the sub-selection-set for objects.
|
|
52
|
+
*
|
|
53
|
+
* v15 has getFieldDef that accepts field name
|
|
54
|
+
* v16 has getFieldDef that accepts field node
|
|
55
|
+
* v17 drops getFieldDef support and adds getField method
|
|
56
|
+
*/
|
|
57
|
+
declare function resolveFieldDef(compilationContext: CompilationContext, parentType: GraphQLObjectType, fieldNodes: FieldNode[]): Maybe<GraphQLField<any, any>>;
|
|
58
|
+
/**
|
|
59
|
+
* v17 introduces `arg.default = { value }` for SDL-built schemas.
|
|
60
|
+
* Programmatic schemas still use `arg.defaultValue`.
|
|
61
|
+
* This helper normalizes both to a single value.
|
|
62
|
+
*/
|
|
63
|
+
declare function getDefaultValue(argOrField: {
|
|
64
|
+
defaultValue?: unknown;
|
|
65
|
+
default?: {
|
|
66
|
+
value?: unknown;
|
|
67
|
+
literal?: unknown;
|
|
68
|
+
};
|
|
69
|
+
}): unknown;
|
|
70
|
+
declare function hasDefaultValue(argOrField: {
|
|
71
|
+
defaultValue?: unknown;
|
|
72
|
+
default?: {
|
|
73
|
+
value?: unknown;
|
|
74
|
+
literal?: unknown;
|
|
75
|
+
};
|
|
76
|
+
}): boolean;
|
|
77
|
+
/**
|
|
78
|
+
* v17 deprecates parseLiteral in favor of coerceInputLiteral for custom scalars
|
|
79
|
+
* However, custom scalars may still only define parseLiteral, so we check
|
|
80
|
+
* for the method's existence rather than just the version.
|
|
81
|
+
*/
|
|
82
|
+
declare function coerceInputLiteral(type: GraphQLScalarType<unknown, unknown>, valueNode: ConstValueNode): any;
|
|
83
|
+
/**
|
|
84
|
+
* V17 removes execution context
|
|
85
|
+
* This is a minimal interface to support the execution context for v16 and v17+
|
|
86
|
+
*/
|
|
87
|
+
interface ExecutionContext$1 {
|
|
88
|
+
errors: Array<GraphQLError> | undefined;
|
|
89
|
+
completed: boolean;
|
|
90
|
+
errorPropagation: boolean;
|
|
91
|
+
}
|
|
92
|
+
|
|
22
93
|
type NullTrimmer = (data: any, errors: GraphQLError[]) => any;
|
|
23
94
|
/**
|
|
24
95
|
*
|
|
@@ -168,50 +239,6 @@ declare function isPromiseInliner(value: string): string;
|
|
|
168
239
|
declare function buildCompilationContext(schema: GraphQLSchema, document: DocumentNode, options: CompilerOptions, operationName?: string): CompilationContext;
|
|
169
240
|
declare function isAsyncIterable<T = unknown>(val: unknown): val is AsyncIterableIterator<T>;
|
|
170
241
|
|
|
171
|
-
/**
|
|
172
|
-
* A helper file to support backward compatibility for different versions of graphql-js.
|
|
173
|
-
*/
|
|
174
|
-
/**
|
|
175
|
-
* v15 does not have schema.getRootType
|
|
176
|
-
* v16 has both
|
|
177
|
-
* v17 will not have getOperationRootType
|
|
178
|
-
*
|
|
179
|
-
* To support all these 3 versions of graphql-js, at least for migration, this helper
|
|
180
|
-
* would be useful.
|
|
181
|
-
*
|
|
182
|
-
* This can be removed once we drop support for v15.
|
|
183
|
-
*
|
|
184
|
-
* GraphQL v17 would remove getOperationRootType.
|
|
185
|
-
*/
|
|
186
|
-
declare function getOperationRootType(schema: GraphQLSchema, operation: OperationDefinitionNode): GraphQLObjectType;
|
|
187
|
-
/**
|
|
188
|
-
* v16 and lower versions don't have .toJSON method on GraphQLError
|
|
189
|
-
* v17 does have .toJSON and doesn't have "formatError" export anymore
|
|
190
|
-
*/
|
|
191
|
-
declare function formatError(error: GraphQLError): GraphQLFormattedError;
|
|
192
|
-
/**
|
|
193
|
-
* v17 dropped support for positional arguments in GraphQLError constructor
|
|
194
|
-
* https://github.com/graphql/graphql-js/pull/3577
|
|
195
|
-
*/
|
|
196
|
-
declare function getGraphQLErrorOptions(nodes: Maybe<ReadonlyArray<ASTNode> | ASTNode>): ConstructorParameters<typeof GraphQLError>[1];
|
|
197
|
-
/**
|
|
198
|
-
* Resolves the field on the given source object. In particular, this
|
|
199
|
-
* figures out the value that the field returns by calling its resolve function,
|
|
200
|
-
* then calls completeValue to complete promises, serialize scalars, or execute
|
|
201
|
-
* the sub-selection-set for objects.
|
|
202
|
-
*
|
|
203
|
-
* v15 has getFieldDef that accepts field name
|
|
204
|
-
* v16 has getFieldDef that accepts field node
|
|
205
|
-
* v17 drops getFieldDef support and adds getField method
|
|
206
|
-
*/
|
|
207
|
-
declare function resolveFieldDef(compilationContext: CompilationContext, parentType: GraphQLObjectType, fieldNodes: FieldNode[]): Maybe<GraphQLField<any, any>>;
|
|
208
|
-
/**
|
|
209
|
-
* v17 deprecates parseLiteral in favor of coerceInputLiteral for custom scalars
|
|
210
|
-
* However, custom scalars may still only define parseLiteral, so we check
|
|
211
|
-
* for the method's existence rather than just the version.
|
|
212
|
-
*/
|
|
213
|
-
declare function coerceInputLiteral(type: GraphQLScalarType<unknown, unknown>, valueNode: ConstValueNode): any;
|
|
214
|
-
|
|
215
242
|
interface JitFieldNode extends FieldNode {
|
|
216
243
|
/**
|
|
217
244
|
* @deprecated Use __internalShouldIncludePath instead
|
|
@@ -299,4 +326,4 @@ declare function serializeObjectPathForSkipInclude(path: ObjectPath | undefined)
|
|
|
299
326
|
*/
|
|
300
327
|
declare function joinSkipIncludePath(a: string, b: string): string;
|
|
301
328
|
|
|
302
|
-
export { type Arguments as A, type CompilationContext as C, type ExecutionContext as E, type FieldsAndNodes as F, GLOBAL_VARIABLES_NAME as G, type JitRuntime as J, type NullTrimmer as N, type ObjectPath as O,
|
|
329
|
+
export { type Arguments as A, flattenPath as B, type CompilationContext as C, serializeObjectPathForSkipInclude as D, type ExecutionContext$1 as E, type FieldsAndNodes as F, GLOBAL_VARIABLES_NAME as G, joinSkipIncludePath as H, type JitRuntime as J, type NullTrimmer as N, type ObjectPath as O, getGraphQLErrorOptions as a, getDefaultValue as b, coerceInputLiteral as c, createNullTrimmer as d, type CompilerOptions as e, formatError as f, getOperationRootType as g, hasDefaultValue as h, type ExecutionContext as i, jitRuntime as j, type CompiledQuery as k, compileQuery as l, isCompiledQuery as m, createBoundQuery as n, isPromise as o, isPromiseInliner as p, buildCompilationContext as q, resolveFieldDef as r, isAsyncIterable as s, type JitFieldNode as t, collectFields as u, collectSubfields as v, getArgumentDefs as w, valueFromAST as x, computeLocations as y, addPath as z };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { k as CompiledQuery, e as CompilerOptions, l as compileQuery, m as isCompiledQuery } from './index-CeluTkd4.mjs';
|
|
2
2
|
export { FieldExpansion, GraphQLJitResolveInfo, LeafField, ResolveInfoEnricherInput, TypeExpansion, fieldExpansionEnricher, isLeafField } from './resolve-info.mjs';
|
|
3
3
|
import '@graphql-typed-document-node/core';
|
|
4
4
|
import 'graphql';
|
|
5
|
-
import 'graphql/execution/execute.js';
|
|
6
5
|
import './types.mjs';
|
|
7
6
|
import './error.mjs';
|
|
8
7
|
import './variables.mjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { k as CompiledQuery, e as CompilerOptions, l as compileQuery, m as isCompiledQuery } from './index-mKv2zpdA.js';
|
|
2
2
|
export { FieldExpansion, GraphQLJitResolveInfo, LeafField, ResolveInfoEnricherInput, TypeExpansion, fieldExpansionEnricher, isLeafField } from './resolve-info.js';
|
|
3
3
|
import '@graphql-typed-document-node/core';
|
|
4
4
|
import 'graphql';
|
|
5
|
-
import 'graphql/execution/execute.js';
|
|
6
5
|
import './types.js';
|
|
7
6
|
import './error.js';
|
|
8
7
|
import './variables.js';
|
package/dist/json.d.mts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { Schema } from 'fast-json-stringify';
|
|
2
|
-
import { C as CompilationContext } from './index-
|
|
2
|
+
import { C as CompilationContext } from './index-CeluTkd4.mjs';
|
|
3
3
|
import '@graphql-typed-document-node/core';
|
|
4
4
|
import 'graphql';
|
|
5
|
-
import 'graphql/execution/execute.js';
|
|
6
5
|
import './types.mjs';
|
|
7
6
|
import './error.mjs';
|
|
8
7
|
import './resolve-info.mjs';
|
package/dist/json.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { Schema } from 'fast-json-stringify';
|
|
2
|
-
import { C as CompilationContext } from './index-
|
|
2
|
+
import { C as CompilationContext } from './index-mKv2zpdA.js';
|
|
3
3
|
import '@graphql-typed-document-node/core';
|
|
4
4
|
import 'graphql';
|
|
5
|
-
import 'graphql/execution/execute.js';
|
|
6
5
|
import './types.js';
|
|
7
6
|
import './error.js';
|
|
8
7
|
import './resolve-info.js';
|
package/dist/non-null.d.mts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import 'graphql';
|
|
2
|
-
export { N as NullTrimmer,
|
|
2
|
+
export { N as NullTrimmer, d as createNullTrimmer } from './index-CeluTkd4.mjs';
|
|
3
3
|
import '@graphql-typed-document-node/core';
|
|
4
|
-
import 'graphql/execution/execute.js';
|
|
5
4
|
import './types.mjs';
|
|
6
5
|
import './error.mjs';
|
|
7
6
|
import './resolve-info.mjs';
|
package/dist/non-null.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import 'graphql';
|
|
2
|
-
export { N as NullTrimmer,
|
|
2
|
+
export { N as NullTrimmer, d as createNullTrimmer } from './index-mKv2zpdA.js';
|
|
3
3
|
import '@graphql-typed-document-node/core';
|
|
4
|
-
import 'graphql/execution/execute.js';
|
|
5
4
|
import './types.js';
|
|
6
5
|
import './error.js';
|
|
7
6
|
import './resolve-info.js';
|
package/dist/runtime.d.mts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
export { J as JitRuntime, j as jitRuntime } from './index-
|
|
1
|
+
export { J as JitRuntime, j as jitRuntime } from './index-CeluTkd4.mjs';
|
|
2
2
|
import '@graphql-typed-document-node/core';
|
|
3
3
|
import 'graphql';
|
|
4
|
-
import 'graphql/execution/execute.js';
|
|
5
4
|
import './types.mjs';
|
|
6
5
|
import './error.mjs';
|
|
7
6
|
import './resolve-info.mjs';
|
package/dist/runtime.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
export { J as JitRuntime, j as jitRuntime } from './index-
|
|
1
|
+
export { J as JitRuntime, j as jitRuntime } from './index-mKv2zpdA.js';
|
|
2
2
|
import '@graphql-typed-document-node/core';
|
|
3
3
|
import 'graphql';
|
|
4
|
-
import 'graphql/execution/execute.js';
|
|
5
4
|
import './types.js';
|
|
6
5
|
import './error.js';
|
|
7
6
|
import './resolve-info.js';
|
package/dist/variables.js
CHANGED
|
@@ -36,6 +36,7 @@ var import_generate = require("./generate");
|
|
|
36
36
|
var import_graphql = require("graphql");
|
|
37
37
|
var import_ast = require("./ast.js");
|
|
38
38
|
var import_error = require("./error.js");
|
|
39
|
+
var import_compat = require("./compat.js");
|
|
39
40
|
var import_inspect = __toESM(require("./inspect.js"));
|
|
40
41
|
const inspect = (0, import_inspect.default)();
|
|
41
42
|
function failToParseVariables(x) {
|
|
@@ -339,7 +340,7 @@ function generateInput(context, varType, varName, hasValueName, defaultValue, wr
|
|
|
339
340
|
field.type,
|
|
340
341
|
field.name,
|
|
341
342
|
hasValueName2,
|
|
342
|
-
field.
|
|
343
|
+
(0, import_compat.hasDefaultValue)(field) ? (0, import_compat.getDefaultValue)(field) : void 0,
|
|
343
344
|
false
|
|
344
345
|
)}
|
|
345
346
|
`);
|
package/dist/variables.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/variables.ts"],"sourcesContent":["import { genFn } from \"./generate\";\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 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 createInspect from \"./inspect.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\nfunction createSubCompilationContext(\n context: CompilationContext\n): CompilationContext {\n return { ...context };\n}\nexport function compileVariableParsing(\n schema: GraphQLSchema,\n varDefNodes: ReadonlyArray<VariableDefinitionNode>\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(`\n return 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 // eslint-disable-next-line\n return Function.apply(\n null,\n [\"GraphQLJITError\", \"inspect\"]\n .concat(Array.from(dependencies.keys()))\n .concat(gen.toString())\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 field.defaultValue,\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAAsB;AACtB,qBAmBO;AACP,iBAA2D;AAC3D,mBAAgD;AAChD,qBAA0B;AAE1B,MAAM,cAAU,eAAAA,SAAc;AAYvB,SAAS,qBAAqB,GAAqC;AACxE,SAAO,EAAE;AACX;AAWA,SAAS,4BACP,SACoB;AACpB,SAAO,EAAE,GAAG,QAAQ;AACtB;AACO,SAAS,uBACd,QACA,aAC2D;AAC3D,QAAM,SAAS,CAAC;AAChB,QAAM,gBAAwC,uBAAO,OAAO,IAAI;AAEhE,MAAI,WAAW;AACf,QAAM,eAAe,oBAAI,IAAI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AK,KAAK,CAAC;AACpD,WAAO,KAAK;AAAA,EACd;AACA,QAAM,eAAe,KAAK,IAAI,UAAU,SAAS,GAAG,CAAC;AACrD,MAAI,OAAO;AACX,WAAS,IAAI,eAAe,GAAG,IAAI,UAAU,QAAQ,EAAE,GAAG;AACxD,YACE,UAAU,CAAC,EAAE,SAAS,YAClB,IAAI,UAAU,CAAC,EAAE,GAAG,KACpB,OAAO,UAAU,CAAC,EAAE,GAAG;AAAA,EAC/B;AACA,SAAO;AACT;","names":["createInspect","GraphQLJITError","hasValueName"]}
|
|
1
|
+
{"version":3,"sources":["../src/variables.ts"],"sourcesContent":["import { genFn } from \"./generate\";\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 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\";\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\nfunction createSubCompilationContext(\n context: CompilationContext\n): CompilationContext {\n return { ...context };\n}\nexport function compileVariableParsing(\n schema: GraphQLSchema,\n varDefNodes: ReadonlyArray<VariableDefinitionNode>\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(`\n return 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 // eslint-disable-next-line\n return Function.apply(\n null,\n [\"GraphQLJITError\", \"inspect\"]\n .concat(Array.from(dependencies.keys()))\n .concat(gen.toString())\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAAsB;AACtB,qBAmBO;AACP,iBAA2D;AAC3D,mBAAgD;AAChD,oBAAiD;AACjD,qBAA0B;AAE1B,MAAM,cAAU,eAAAA,SAAc;AAYvB,SAAS,qBAAqB,GAAqC;AACxE,SAAO,EAAE;AACX;AAWA,SAAS,4BACP,SACoB;AACpB,SAAO,EAAE,GAAG,QAAQ;AACtB;AACO,SAAS,uBACd,QACA,aAC2D;AAC3D,QAAM,SAAS,CAAC;AAChB,QAAM,gBAAwC,uBAAO,OAAO,IAAI;AAEhE,MAAI,WAAW;AACf,QAAM,eAAe,oBAAI,IAAI;AAC7B,aAAW,cAAc,aAAa;AACpC,UAAM,UAA8B;AAAA,MAClC;AAAA,MACA,OAAO;AAAA,MACP,eAAW,oBAAQ,QAAW,OAAO;AAAA,MACrC,kBAAc,oBAAQ,QAAW,SAAS;AAAA,MAC1C;AAAA,IACF;AACA,UAAM,UAAU,WAAW,SAAS,KAAK;AACzC,UAAM,cAAU,4BAAY,QAAQ,WAAW,IAAW;AAC1D,QAAI,CAAC,WAAW,KAAC,4BAAY,OAAO,GAAG;AAGrC,aAAO;AAAA,QACL,IAAK,aAAAC;AAAA,UACH,cAAc,OAAO,6BAEjB,eAAW,sBAAM,WAAW,IAAI,CAClC;AAA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 -16,6 +16,7 @@ import {
|
|
|
16
16
|
} from "graphql";
|
|
17
17
|
import { addPath, computeLocations } from "./ast.js";
|
|
18
18
|
import { GraphQLError as GraphQLJITError } from "./error.js";
|
|
19
|
+
import { getDefaultValue, hasDefaultValue } from "./compat.js";
|
|
19
20
|
import createInspect from "./inspect.js";
|
|
20
21
|
const inspect = createInspect();
|
|
21
22
|
function failToParseVariables(x) {
|
|
@@ -319,7 +320,7 @@ function generateInput(context, varType, varName, hasValueName, defaultValue, wr
|
|
|
319
320
|
field.type,
|
|
320
321
|
field.name,
|
|
321
322
|
hasValueName2,
|
|
322
|
-
field
|
|
323
|
+
hasDefaultValue(field) ? getDefaultValue(field) : void 0,
|
|
323
324
|
false
|
|
324
325
|
)}
|
|
325
326
|
`);
|
package/dist/variables.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/variables.ts"],"sourcesContent":["import { genFn } from \"./generate\";\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 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 createInspect from \"./inspect.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\nfunction createSubCompilationContext(\n context: CompilationContext\n): CompilationContext {\n return { ...context };\n}\nexport function compileVariableParsing(\n schema: GraphQLSchema,\n varDefNodes: ReadonlyArray<VariableDefinitionNode>\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(`\n return 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 // eslint-disable-next-line\n return Function.apply(\n null,\n [\"GraphQLJITError\", \"inspect\"]\n .concat(Array.from(dependencies.keys()))\n .concat(gen.toString())\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 field.defaultValue,\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"],"mappings":"AAAA,SAAS,aAAa;AACtB;AAAA,EACE;AAAA,EAEA;AAAA,EACA;AAAA,EAEA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,SAAS,wBAAyC;AAC3D,SAAS,gBAAgB,uBAAuB;AAChD,OAAO,mBAAmB;AAE1B,MAAM,UAAU,cAAc;AAYvB,SAAS,qBAAqB,GAAqC;AACxE,SAAO,EAAE;AACX;AAWA,SAAS,4BACP,SACoB;AACpB,SAAO,EAAE,GAAG,QAAQ;AACtB;AACO,SAAS,uBACd,QACA,aAC2D;AAC3D,QAAM,SAAS,CAAC;AAChB,QAAM,gBAAwC,uBAAO,OAAO,IAAI;AAEhE,MAAI,WAAW;AACf,QAAM,eAAe,oBAAI,IAAI;AAC7B,aAAW,cAAc,aAAa;AACpC,UAAM,UAA8B;AAAA,MAClC;AAAA,MACA,OAAO;AAAA,MACP,WAAW,QAAQ,QAAW,OAAO;AAAA,MACrC,cAAc,QAAQ,QAAW,SAAS;AAAA,MAC1C;AAAA,IACF;AACA,UAAM,UAAU,WAAW,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KACpB,OAAO,UAAU,CAAC,EAAE,GAAG;AAAA,EAC/B;AACA,SAAO;AACT;","names":["hasValueName"]}
|
|
1
|
+
{"version":3,"sources":["../src/variables.ts"],"sourcesContent":["import { genFn } from \"./generate\";\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 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\";\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\nfunction createSubCompilationContext(\n context: CompilationContext\n): CompilationContext {\n return { ...context };\n}\nexport function compileVariableParsing(\n schema: GraphQLSchema,\n varDefNodes: ReadonlyArray<VariableDefinitionNode>\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(`\n return 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 // eslint-disable-next-line\n return Function.apply(\n null,\n [\"GraphQLJITError\", \"inspect\"]\n .concat(Array.from(dependencies.keys()))\n .concat(gen.toString())\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"],"mappings":"AAAA,SAAS,aAAa;AACtB;AAAA,EACE;AAAA,EAEA;AAAA,EACA;AAAA,EAEA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,SAAS,wBAAyC;AAC3D,SAAS,gBAAgB,uBAAuB;AAChD,SAAS,iBAAiB,uBAAuB;AACjD,OAAO,mBAAmB;AAE1B,MAAM,UAAU,cAAc;AAYvB,SAAS,qBAAqB,GAAqC;AACxE,SAAO,EAAE;AACX;AAWA,SAAS,4BACP,SACoB;AACpB,SAAO,EAAE,GAAG,QAAQ;AACtB;AACO,SAAS,uBACd,QACA,aAC2D;AAC3D,QAAM,SAAS,CAAC;AAChB,QAAM,gBAAwC,uBAAO,OAAO,IAAI;AAEhE,MAAI,WAAW;AACf,QAAM,eAAe,oBAAI,IAAI;AAC7B,aAAW,cAAc,aAAa;AACpC,UAAM,UAA8B;AAAA,MAClC;AAAA,MACA,OAAO;AAAA,MACP,WAAW,QAAQ,QAAW,OAAO;AAAA,MACrC,cAAc,QAAQ,QAAW,SAAS;AAAA,MAC1C;AAAA,IACF;AACA,UAAM,UAAU,WAAW,SAAS,KAAK;AACzC,UAAM,UAAU,YAAY,QAAQ,WAAW,IAAW;AAC1D,QAAI,CAAC,WAAW,CAAC,YAAY,OAAO,GAAG;AAGrC,aAAO;AAAA,QACL,IAAK;AAAA,UACH,cAAc,OAAO,6BAEjB,WAAW,MAAM,WAAW,IAAI,CAClC;AAAA,UACF,iBAAiB,CAAC,WAAW,IAAI,CAAC;AAAA,QACpC;AAAA,MACF;AACA;AAAA,IACF;AAGA,kBAAc,OAAO,IAAI;AACzB,UAAM,eAAe,SAAS,QAAQ,QAAQ,WAAW,OAAO,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A,EACd;AACA,SAAO,WAAW,UAAU,KAAK,GAAG,CAAC;AACvC;AAEA,SAAS,mBAAmB,UAA4B;AACtD,SAAO,KAAK,UAAU,QAAQ;AAChC;AAEA,SAAS,cAAc,MAA0B;AAC/C,QAAM,YAAY,CAAC;AACnB,MAAI,OAA+B;AACnC,SAAO,MAAM;AACX,cAAU,QAAQ,EAAE,KAAK,KAAK,KAAK,MAAM,KAAK,KAAK,CAAC;AACpD,WAAO,KAAK;AAAA,EACd;AACA,MAAI,OAAO,UAAU,CAAC,EAAE;AACxB,WAAS,IAAI,GAAG,IAAI,UAAU,QAAQ,EAAE,GAAG;AACzC,YACE,UAAU,CAAC,EAAE,SAAS,YAClB,KAAK,UAAU,CAAC,EAAE,GAAG,OACrB,IAAI,UAAU,CAAC,EAAE,GAAG;AAAA,EAC5B;AACA,SAAO;AACT;AAEA,SAAS,gBAAgB,MAAkB;AACzC,QAAM,YAAY,CAAC;AACnB,MAAI,OAA+B;AACnC,SAAO,MAAM;AACX,cAAU,QAAQ,EAAE,KAAK,KAAK,KAAK,MAAM,KAAK,KAAK,CAAC;AACpD,WAAO,KAAK;AAAA,EACd;AACA,QAAM,eAAe,KAAK,IAAI,UAAU,SAAS,GAAG,CAAC;AACrD,MAAI,OAAO;AACX,WAAS,IAAI,eAAe,GAAG,IAAI,UAAU,QAAQ,EAAE,GAAG;AACxD,YACE,UAAU,CAAC,EAAE,SAAS,YAClB,IAAI,UAAU,CAAC,EAAE,GAAG,KACpB,OAAO,UAAU,CAAC,EAAE,GAAG;AAAA,EAC/B;AACA,SAAO;AACT;","names":["hasValueName"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "graphql-jit",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.9",
|
|
4
4
|
"description": "GraphQL JIT Compiler to JS",
|
|
5
5
|
"author": "Rui Araujo",
|
|
6
6
|
"license": "MIT",
|
|
@@ -105,7 +105,7 @@
|
|
|
105
105
|
"eslint-config-prettier": "^9.1.0",
|
|
106
106
|
"eslint-plugin-prettier": "^5.2.1",
|
|
107
107
|
"globals": "^15.9.0",
|
|
108
|
-
"graphql": "^
|
|
108
|
+
"graphql": "^17.0.1",
|
|
109
109
|
"jest": "^29.7.0",
|
|
110
110
|
"lint-staged": "^14.0.1",
|
|
111
111
|
"prettier": "^3.0.3",
|
|
@@ -115,7 +115,7 @@
|
|
|
115
115
|
},
|
|
116
116
|
"dependencies": {
|
|
117
117
|
"@graphql-typed-document-node/core": "^3.2.0",
|
|
118
|
-
"fast-json-stringify": "^
|
|
118
|
+
"fast-json-stringify": "^7.0.1",
|
|
119
119
|
"generate-function": "^2.3.1",
|
|
120
120
|
"lodash.memoize": "^4.1.2",
|
|
121
121
|
"lodash.merge": "4.6.2",
|