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/compat.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compat.js","sourceRoot":"","sources":["../../src/compat.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AACnC,OAAO,EAGL,WAAW,EAWX,kBAAkB,EAClB,gBAAgB,EAChB,oBAAoB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E;IAC1E,IAAI,WAAW,CAAC,KAAK,IAAI,EAAE,IAAK,IAAY,CAAC,kBAAkB,EAAE,CAAC;QAChE,OAAQ,IAAY,CAAC,kBAAkB,CAAC,SAAS,CAAC,CAAC;IACrD,CAAC;IAED,OAAQ,IAAY,CAAC,YAAY,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;AACnD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAC/B,IAA2D,EAC3D,KAAc;IAEd,MAAM,CAAC,GAAG,IAAW,CAAC;IACtB,OAAO,WAAW,CAAC,KAAK,IAAI,EAAE,IAAI,CAAC,CAAC,iBAAiB;QACnD,CAAC,CAAC,CAAC,CAAC,iBAAiB,CAAC,KAAK,CAAC;QAC5B,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;AACzB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAC9B,IAA2D,EAC3D,KAAc;IAEd,MAAM,CAAC,GAAG,IAAW,CAAC;IACtB,OAAO,WAAW,CAAC,KAAK,IAAI,EAAE,IAAI,CAAC,CAAC,gBAAgB;QAClD,CAAC,CAAC,CAAC,CAAC,gBAAgB,CAAC,KAAK,CAAC;QAC3B,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;AAC1B,CAAC","sourcesContent":["import * as graphql from \"graphql\";\nimport {\n GraphQLSchema,\n GraphQLError,\n versionInfo,\n type FieldNode,\n type GraphQLField,\n type ASTNode,\n type OperationDefinitionNode,\n type GraphQLObjectType,\n type GraphQLFormattedError,\n type ConstValueNode,\n type GraphQLInputType,\n type GraphQLEnumType,\n GraphQLScalarType,\n SchemaMetaFieldDef,\n TypeMetaFieldDef,\n TypeNameMetaFieldDef\n} from \"graphql\";\nimport { type Maybe } from \"./types.js\";\nimport { type CompilationContext } from \"./execution.js\";\n\n/**\n * A helper file to support backward compatibility for different versions of graphql-js.\n */\n\n/**\n * v15 does not have schema.getRootType\n * v16 has both\n * v17 will not have getOperationRootType\n *\n * To support all these 3 versions of graphql-js, at least for migration, this helper\n * would be useful.\n *\n * This can be removed once we drop support for v15.\n *\n * GraphQL v17 would remove getOperationRootType.\n */\nexport function getOperationRootType(\n schema: GraphQLSchema,\n operation: OperationDefinitionNode\n): GraphQLObjectType {\n if (versionInfo.major < 16) {\n return (graphql as any).getOperationRootType(schema, operation);\n }\n\n const type = (schema as any).getRootType(operation.operation);\n\n if (!type) {\n throw new Error(`No root type for operation ${operation.operation}`);\n }\n\n return type;\n}\n\n/**\n * v16 and lower versions don't have .toJSON method on GraphQLError\n * v17 does have .toJSON and doesn't have \"formatError\" export anymore\n */\nexport function formatError(error: GraphQLError): GraphQLFormattedError {\n if (versionInfo.major < 16) {\n return (graphql as any).formatError(error);\n }\n\n return (error as any).toJSON();\n}\n\n/**\n * v17 dropped support for positional arguments in GraphQLError constructor\n * https://github.com/graphql/graphql-js/pull/3577\n */\nexport function getGraphQLErrorOptions(\n nodes: Maybe<ReadonlyArray<ASTNode> | ASTNode>\n): ConstructorParameters<typeof GraphQLError>[1] {\n if (versionInfo.major < 16) {\n return nodes as any;\n }\n\n return { nodes } as any;\n}\n\n/**\n * Resolves the field on the given source object. In particular, this\n * figures out the value that the field returns by calling its resolve function,\n * then calls completeValue to complete promises, serialize scalars, or execute\n * the sub-selection-set for objects.\n */\nexport function resolveFieldDef(\n compilationContext: CompilationContext,\n parentType: GraphQLObjectType,\n fieldNodes: FieldNode[]\n): Maybe<GraphQLField<any, any>> {\n const fieldNode = fieldNodes[0];\n const fieldName = fieldNode.name.value;\n\n if (versionInfo.major < 17) {\n const schema = compilationContext.schema;\n if (\n fieldName === SchemaMetaFieldDef.name &&\n schema.getQueryType() === parentType\n ) {\n return SchemaMetaFieldDef;\n }\n if (\n fieldName === TypeMetaFieldDef.name &&\n schema.getQueryType() === parentType\n ) {\n return TypeMetaFieldDef;\n }\n if (fieldName === TypeNameMetaFieldDef.name) {\n return TypeNameMetaFieldDef;\n }\n return parentType.getFields()[fieldName];\n }\n\n return (compilationContext.schema as any).getField(parentType, fieldName);\n}\n\ninterface DefaultCarrier {\n type: GraphQLInputType;\n defaultValue?: unknown;\n default?: { value?: unknown; literal?: ConstValueNode };\n}\n\n/**\n * v17 SDL-built schemas store defaults as `default = { literal }` (an AST\n * node that must be coerced against the type); programmatic v17 schemas use\n * `default = { value }`, and v16 and lower use `defaultValue`.\n */\nexport function getDefaultValue(argOrField: DefaultCarrier): unknown {\n const def = argOrField.default;\n if (def !== undefined) {\n if (def.literal !== undefined) {\n return (graphql as any).coerceInputLiteral(def.literal, argOrField.type);\n }\n return def.value;\n }\n return argOrField.defaultValue;\n}\n\nexport function hasDefaultValue(argOrField: DefaultCarrier): boolean {\n return (\n argOrField.default !== undefined || argOrField.defaultValue !== undefined\n );\n}\n\n/**\n * v17 deprecates parseLiteral in favor of coerceInputLiteral for custom scalars.\n * Custom scalars may still only define parseLiteral, so on v17 we also check\n * for the method's existence.\n */\nexport function coerceInputLiteral(\n type: GraphQLScalarType<unknown, unknown>,\n valueNode: ConstValueNode\n): any {\n // Use coerceInputLiteral if available (built-in scalars in v17+).\n // Otherwise fall back to parseLiteral (custom scalars, or v16 and lower).\n if (versionInfo.major >= 17 && (type as any).coerceInputLiteral) {\n return (type as any).coerceInputLiteral(valueNode);\n }\n\n return (type as any).parseLiteral(valueNode, {});\n}\n\n/**\n * v17 prefers `coerceOutputValue` over the legacy `serialize`, and the two\n * can differ when both are defined. Custom scalars may define only one.\n */\nexport function coerceOutputValue(\n type: GraphQLScalarType<unknown, unknown> | GraphQLEnumType,\n value: unknown\n): unknown {\n const t = type as any;\n return versionInfo.major >= 17 && t.coerceOutputValue\n ? t.coerceOutputValue(value)\n : t.serialize(value);\n}\n\n/**\n * v17 prefers `coerceInputValue` over the legacy `parseValue`, and the two\n * can differ when both are defined. Custom scalars may define only one.\n */\nexport function coerceInputValue(\n type: GraphQLScalarType<unknown, unknown> | GraphQLEnumType,\n value: unknown\n): unknown {\n const t = type as any;\n return versionInfo.major >= 17 && t.coerceInputValue\n ? t.coerceInputValue(value)\n : t.parseValue(value);\n}\n\n/**\n * V17 removes execution context\n * This is a minimal interface to support the execution context for v16 and v17+\n */\nexport interface ExecutionContext {\n errors: Array<GraphQLError> | undefined;\n completed: boolean;\n errorPropagation: boolean;\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type GraphQLInputType } from "graphql";
|
|
2
|
+
/**
|
|
3
|
+
* Emits a coerced input value as a JS expression. Lists and input objects are
|
|
4
|
+
* emitted inline, so every execution gets fresh containers that variables can
|
|
5
|
+
* be written into. Scalar and enum values are internal values that need not be
|
|
6
|
+
* serializable (bigint, Date, class instances...), so non-primitive ones are
|
|
7
|
+
* stored outside the source with `bind`, which returns the expression to read
|
|
8
|
+
* them back.
|
|
9
|
+
*/
|
|
10
|
+
export declare function compileInputValue(val: any, type: GraphQLInputType, bind: (value: any) => string): string;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { isInputObjectType, isLeafType, isListType, isNonNullType } from "graphql";
|
|
2
|
+
/**
|
|
3
|
+
* Emits a coerced input value as a JS expression. Lists and input objects are
|
|
4
|
+
* emitted inline, so every execution gets fresh containers that variables can
|
|
5
|
+
* be written into. Scalar and enum values are internal values that need not be
|
|
6
|
+
* serializable (bigint, Date, class instances...), so non-primitive ones are
|
|
7
|
+
* stored outside the source with `bind`, which returns the expression to read
|
|
8
|
+
* them back.
|
|
9
|
+
*/
|
|
10
|
+
export function compileInputValue(val, type, bind) {
|
|
11
|
+
if (val == null) {
|
|
12
|
+
return String(val);
|
|
13
|
+
}
|
|
14
|
+
if (isNonNullType(type)) {
|
|
15
|
+
return compileInputValue(val, type.ofType, bind);
|
|
16
|
+
}
|
|
17
|
+
if (isLeafType(type)) {
|
|
18
|
+
switch (typeof val) {
|
|
19
|
+
case "number":
|
|
20
|
+
// JSON.stringify would turn NaN/Infinity into null
|
|
21
|
+
return Number.isFinite(val) ? JSON.stringify(val) : String(val);
|
|
22
|
+
case "string":
|
|
23
|
+
case "boolean":
|
|
24
|
+
return JSON.stringify(val);
|
|
25
|
+
default:
|
|
26
|
+
return bind(val);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if (isListType(type)) {
|
|
30
|
+
if (Object.getPrototypeOf(val) !== Array.prototype) {
|
|
31
|
+
// a programmatic default that is not a plain array, e.g. an array
|
|
32
|
+
// subclass, is passed as is, like GraphQL.js does
|
|
33
|
+
return bind(val);
|
|
34
|
+
}
|
|
35
|
+
return `[${val
|
|
36
|
+
.map((item) => compileInputValue(item, type.ofType, bind))
|
|
37
|
+
.join(",")}]`;
|
|
38
|
+
}
|
|
39
|
+
if (isInputObjectType(type)) {
|
|
40
|
+
const proto = Object.getPrototypeOf(val);
|
|
41
|
+
if (proto !== Object.prototype && proto !== null) {
|
|
42
|
+
// a programmatic default that is a class instance is passed as is,
|
|
43
|
+
// like GraphQL.js does
|
|
44
|
+
return bind(val);
|
|
45
|
+
}
|
|
46
|
+
const fields = type.getFields();
|
|
47
|
+
const props = [];
|
|
48
|
+
for (const key of Object.keys(val)) {
|
|
49
|
+
// unknown keys of a programmatic default are passed as is
|
|
50
|
+
const value = fields[key]
|
|
51
|
+
? compileInputValue(val[key], fields[key].type, bind)
|
|
52
|
+
: bind(val[key]);
|
|
53
|
+
props.push(`${JSON.stringify(key)}:${value}`);
|
|
54
|
+
}
|
|
55
|
+
return `{${props.join(",")}}`;
|
|
56
|
+
}
|
|
57
|
+
/* istanbul ignore next */
|
|
58
|
+
throw new Error(`Unexpected input type: "${type}".`);
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=compile-input.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compile-input.js","sourceRoot":"","sources":["../../src/compile-input.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,iBAAiB,EACjB,UAAU,EACV,UAAU,EACV,aAAa,EACd,MAAM,SAAS,CAAC;AAEjB;;;;;;;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AM,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC;QACzC,IAAI,KAAK,KAAK,MAAM,CAAC,SAAS,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;YACjD,mEAAmE;YACnE,uBAAuB;YACvB,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;QACnB,CAAC;QACD,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;QAChC,MAAM,KAAK,GAAG,EAAE,CAAC;QACjB,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;YACnC,0DAA0D;YAC1D,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC;gBACvB,CAAC,CAAC,iBAAiB,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC;gBACrD,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;YACnB,KAAK,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,KAAK,EAAE,CAAC,CAAC;QAChD,CAAC;QACD,OAAO,IAAI,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;IAChC,CAAC;IACD,0BAA0B;IAC1B,MAAM,IAAI,KAAK,CAAC,2BAA2B,IAAI,IAAI,CAAC,CAAC;AACvD,CAAC","sourcesContent":["import {\n type GraphQLInputType,\n isInputObjectType,\n isLeafType,\n isListType,\n isNonNullType\n} from \"graphql\";\n\n/**\n * Emits a coerced input value as a JS expression. Lists and input objects are\n * emitted inline, so every execution gets fresh containers that variables can\n * be written into. Scalar and enum values are internal values that need not be\n * serializable (bigint, Date, class instances...), so non-primitive ones are\n * stored outside the source with `bind`, which returns the expression to read\n * them back.\n */\nexport function compileInputValue(\n val: any,\n type: GraphQLInputType,\n bind: (value: any) => string\n): string {\n if (val == null) {\n return String(val);\n }\n if (isNonNullType(type)) {\n return compileInputValue(val, type.ofType, bind);\n }\n if (isLeafType(type)) {\n switch (typeof val) {\n case \"number\":\n // JSON.stringify would turn NaN/Infinity into null\n return Number.isFinite(val) ? JSON.stringify(val) : String(val);\n case \"string\":\n case \"boolean\":\n return JSON.stringify(val);\n default:\n return bind(val);\n }\n }\n if (isListType(type)) {\n if (Object.getPrototypeOf(val) !== Array.prototype) {\n // a programmatic default that is not a plain array, e.g. an array\n // subclass, is passed as is, like GraphQL.js does\n return bind(val);\n }\n return `[${val\n .map((item: unknown) => compileInputValue(item, type.ofType, bind))\n .join(\",\")}]`;\n }\n if (isInputObjectType(type)) {\n const proto = Object.getPrototypeOf(val);\n if (proto !== Object.prototype && proto !== null) {\n // a programmatic default that is a class instance is passed as is,\n // like GraphQL.js does\n return bind(val);\n }\n const fields = type.getFields();\n const props = [];\n for (const key of Object.keys(val)) {\n // unknown keys of a programmatic default are passed as is\n const value = fields[key]\n ? compileInputValue(val[key], fields[key].type, bind)\n : bind(val[key]);\n props.push(`${JSON.stringify(key)}:${value}`);\n }\n return `{${props.join(\",\")}}`;\n }\n /* istanbul ignore next */\n throw new Error(`Unexpected input type: \"${type}\".`);\n}\n"]}
|
package/dist/esm/execution.d.ts
CHANGED
package/dist/esm/execution.js
CHANGED
|
@@ -6,9 +6,10 @@ const GLOBAL_RUNTIME_NAME = "__context.rt";
|
|
|
6
6
|
import { GraphQLEnumType, GraphQLError, isAbstractType, isLeafType, isListType, isNonNullType, isObjectType, isSpecifiedScalarType, Kind, locatedError, responsePathAsArray, TypeNameMetaFieldDef } from "graphql";
|
|
7
7
|
import { addPath, collectFields, collectSubfields, computeLocations, flattenPath, getArgumentDefs, joinSkipIncludePath, resolveFieldDef, serializeObjectPathForSkipInclude } from "./ast.js";
|
|
8
8
|
import { GraphQLError as GraphqlJitError } from "./error.js";
|
|
9
|
+
import { compileInputValue } from "./compile-input.js";
|
|
9
10
|
import createInspect from "./inspect.js";
|
|
10
11
|
import { queryToJSONSchema } from "./json.js";
|
|
11
|
-
import { createNullTrimmer } from "./non-null.js";
|
|
12
|
+
import { createNullTrimmer, createRootNullChecker } from "./non-null.js";
|
|
12
13
|
import { createResolveInfoThunk } from "./resolve-info.js";
|
|
13
14
|
import { compileVariableParsing, failToParseVariables } from "./variables.js";
|
|
14
15
|
import { coerceOutputValue, getGraphQLErrorOptions, getOperationRootType } from "./compat.js";
|
|
@@ -18,6 +19,8 @@ const SAFETY_CHECK_PREFIX = "__validNode";
|
|
|
18
19
|
const GLOBAL_DATA_NAME = "__context.data";
|
|
19
20
|
const GLOBAL_ERRORS_NAME = "__context.errors";
|
|
20
21
|
const GLOBAL_NULL_ERRORS_NAME = "__context.nullErrors";
|
|
22
|
+
// Key in `literals` of the check for errors that null the whole response.
|
|
23
|
+
const NULLS_RESPONSE_LITERAL = "nullsResponse";
|
|
21
24
|
const GLOBAL_ROOT_NAME = "__context.rootValue";
|
|
22
25
|
export const GLOBAL_VARIABLES_NAME = "__context.variables";
|
|
23
26
|
const GLOBAL_CONTEXT_NAME = "__context.context";
|
|
@@ -198,6 +201,7 @@ function compileOperation(context, type, fieldMap) {
|
|
|
198
201
|
"use strict";
|
|
199
202
|
`;
|
|
200
203
|
if (serialExecution) {
|
|
204
|
+
context.literals[NULLS_RESPONSE_LITERAL] = createRootNullChecker(context);
|
|
201
205
|
body += `${GLOBAL_EXECUTION_CONTEXT}.queue = [];`;
|
|
202
206
|
}
|
|
203
207
|
body += generateUniqueDeclarations(context, true);
|
|
@@ -207,8 +211,12 @@ function compileOperation(context, type, fieldMap) {
|
|
|
207
211
|
body += `
|
|
208
212
|
${GLOBAL_EXECUTION_CONTEXT}.finalResolve = () => {};
|
|
209
213
|
${GLOBAL_RESOLVE} = (context) => {
|
|
210
|
-
|
|
211
|
-
|
|
214
|
+
// Stop when all mutations have finished, or when an error in a non-null
|
|
215
|
+
// field has nulled the whole response.
|
|
216
|
+
if (
|
|
217
|
+
context.jobCounter >= context.queue.length ||
|
|
218
|
+
context.literals.${NULLS_RESPONSE_LITERAL}(context.nullErrors)
|
|
219
|
+
) {
|
|
212
220
|
context.finalResolve(context);
|
|
213
221
|
return;
|
|
214
222
|
}
|
|
@@ -287,7 +295,10 @@ function compileDeferredField(context, deferredField, appendix) {
|
|
|
287
295
|
}
|
|
288
296
|
}
|
|
289
297
|
);
|
|
290
|
-
}
|
|
298
|
+
}${
|
|
299
|
+
// Invalid arguments skip the resolver and its handler, which is also what
|
|
300
|
+
// advances a serial (mutation) queue.
|
|
301
|
+
appendix ? ` else {${appendix}}` : ""}`;
|
|
291
302
|
context.hoistedFunctions.push(`
|
|
292
303
|
function ${resolverHandler}(${GLOBAL_EXECUTION_CONTEXT}, ${GLOBAL_PARENT_NAME}, ${jsFieldName}, ${parentIndexes}) {
|
|
293
304
|
${generateUniqueDeclarations(subContext)}
|
|
@@ -704,72 +715,6 @@ function compileListType(context, parentType, type, fieldNodes, originalObjectPa
|
|
|
704
715
|
return `(typeof ${name} === "string" || typeof ${name}[Symbol.iterator] !== "function") ? ${errorCase} :
|
|
705
716
|
${GLOBAL_SAFE_MAP_NAME}(${GLOBAL_EXECUTION_CONTEXT}, ${name}, ${safeMapHandler}, ${parentIndexes})`;
|
|
706
717
|
}
|
|
707
|
-
/**
|
|
708
|
-
* Whether the value cannot be written into source as a literal: a bigint,
|
|
709
|
-
* symbol, function, or any object other than a plain object, array or Date.
|
|
710
|
-
*/
|
|
711
|
-
function isUnserializable(value) {
|
|
712
|
-
switch (typeof value) {
|
|
713
|
-
case "bigint":
|
|
714
|
-
case "symbol":
|
|
715
|
-
case "function":
|
|
716
|
-
return true;
|
|
717
|
-
case "object": {
|
|
718
|
-
if (value === null) {
|
|
719
|
-
return false;
|
|
720
|
-
}
|
|
721
|
-
const proto = Object.getPrototypeOf(value);
|
|
722
|
-
if (Array.isArray(value)) {
|
|
723
|
-
return proto !== Array.prototype;
|
|
724
|
-
}
|
|
725
|
-
if (value instanceof Date) {
|
|
726
|
-
return proto !== Date.prototype;
|
|
727
|
-
}
|
|
728
|
-
return proto !== null && proto !== Object.prototype;
|
|
729
|
-
}
|
|
730
|
-
default:
|
|
731
|
-
return false;
|
|
732
|
-
}
|
|
733
|
-
}
|
|
734
|
-
/**
|
|
735
|
-
* Serializes an argument value to a JS expression. Unserializable values are
|
|
736
|
-
* stored via `hoist` and referenced from `context.literals`.
|
|
737
|
-
*/
|
|
738
|
-
function objectStringify(val, hoist) {
|
|
739
|
-
if (isUnserializable(val)) {
|
|
740
|
-
return `${GLOBAL_EXECUTION_CONTEXT}.literals.${hoist(val)}`;
|
|
741
|
-
}
|
|
742
|
-
if (typeof val === "number") {
|
|
743
|
-
// JSON.stringify would turn NaN/Infinity into null
|
|
744
|
-
return Number.isFinite(val) ? JSON.stringify(val) : String(val);
|
|
745
|
-
}
|
|
746
|
-
if (val === undefined) {
|
|
747
|
-
return "undefined";
|
|
748
|
-
}
|
|
749
|
-
if (val === null || typeof val !== "object") {
|
|
750
|
-
return JSON.stringify(val);
|
|
751
|
-
}
|
|
752
|
-
if (val instanceof Date) {
|
|
753
|
-
return `new Date(${val.getTime()})`;
|
|
754
|
-
}
|
|
755
|
-
if (Array.isArray(val)) {
|
|
756
|
-
const items = [];
|
|
757
|
-
for (let i = 0; i < val.length; ++i) {
|
|
758
|
-
items.push(i in val ? objectStringify(val[i], hoist) : "null");
|
|
759
|
-
}
|
|
760
|
-
return `[${items.join(",")}]`;
|
|
761
|
-
}
|
|
762
|
-
const props = [];
|
|
763
|
-
for (const key of Object.keys(val)) {
|
|
764
|
-
if (val[key] === undefined) {
|
|
765
|
-
continue;
|
|
766
|
-
}
|
|
767
|
-
// a computed key stops "__proto__" from setting the prototype
|
|
768
|
-
const name = JSON.stringify(key);
|
|
769
|
-
props.push(`${key === "__proto__" ? `[${name}]` : name}:${objectStringify(val[key], hoist)}`);
|
|
770
|
-
}
|
|
771
|
-
return `{${props.join(",")}}`;
|
|
772
|
-
}
|
|
773
718
|
/**
|
|
774
719
|
* Calculates a GraphQLResolveInfo object for the resolver calls.
|
|
775
720
|
*
|
|
@@ -830,14 +775,18 @@ function objectPath(topLevel, path) {
|
|
|
830
775
|
* @returns {string}
|
|
831
776
|
*/
|
|
832
777
|
function compileArguments(context, args, topLevelArg, validArgs, returnType, path) {
|
|
778
|
+
const bind = (value) => {
|
|
779
|
+
const key = `literal${context.literalCount.value++}`;
|
|
780
|
+
context.literals[key] = value;
|
|
781
|
+
return `${GLOBAL_EXECUTION_CONTEXT}.literals.${key}`;
|
|
782
|
+
};
|
|
783
|
+
const valuesExpression = `{${Object.keys(args.values)
|
|
784
|
+
.map((name) => `${JSON.stringify(name)}:${compileInputValue(args.values[name], args.types[name], bind)}`)
|
|
785
|
+
.join(",")}}`;
|
|
833
786
|
// default to assuming arguments are valid
|
|
834
787
|
let body = `
|
|
835
788
|
let ${validArgs} = true;
|
|
836
|
-
const ${topLevelArg} = ${
|
|
837
|
-
const key = `literal${Object.keys(context.literals).length}`;
|
|
838
|
-
context.literals[key] = value;
|
|
839
|
-
return key;
|
|
840
|
-
})};
|
|
789
|
+
const ${topLevelArg} = ${valuesExpression};
|
|
841
790
|
`;
|
|
842
791
|
const errorDestination = getErrorDestination(returnType);
|
|
843
792
|
for (const variable of args.missing) {
|
|
@@ -1052,6 +1001,7 @@ export function buildCompilationContext(schema, document, options, operationName
|
|
|
1052
1001
|
isTypeOfs: {},
|
|
1053
1002
|
resolveInfos: {},
|
|
1054
1003
|
literals: {},
|
|
1004
|
+
literalCount: { value: 0 },
|
|
1055
1005
|
hoistedFunctions: [],
|
|
1056
1006
|
hoistedFunctionNames: new Map(),
|
|
1057
1007
|
leafErrHandlerCache: new Map(),
|