graphql-jit
Advanced tools
Comparing version 0.8.2 to 0.8.3
@@ -34,3 +34,2 @@ "use strict"; | ||
function collectFieldsImpl(compilationContext, runtimeType, selectionSet, fields, visitedFragmentNames, previousShouldInclude = "", parentResponsePath = "") { | ||
var _a, _b, _c; | ||
for (const selection of selectionSet.selections) { | ||
@@ -52,4 +51,2 @@ switch (selection.kind) { | ||
const compiledSkipInclude = compileSkipInclude(compilationContext, selection); | ||
if (!fieldNode.__internalShouldIncludePath) | ||
fieldNode.__internalShouldIncludePath = {}; | ||
/** | ||
@@ -72,8 +69,10 @@ * Carry over fragment's skip and include code | ||
if (compilationContext.options.useExperimentalPathBasedSkipInclude) { | ||
if (!fieldNode.__internalShouldIncludePath) | ||
fieldNode.__internalShouldIncludePath = {}; | ||
fieldNode.__internalShouldIncludePath[currentPath] = | ||
joinShouldIncludeCompilations((_b = (_a = fieldNode.__internalShouldIncludePath) === null || _a === void 0 ? void 0 : _a[currentPath]) !== null && _b !== void 0 ? _b : "", previousShouldInclude, compiledSkipInclude); | ||
joinShouldIncludeCompilations(fieldNode.__internalShouldIncludePath?.[currentPath] ?? "", previousShouldInclude, compiledSkipInclude); | ||
} | ||
else { | ||
// @deprecated | ||
fieldNode.__internalShouldInclude = joinShouldIncludeCompilations((_c = fieldNode.__internalShouldInclude) !== null && _c !== void 0 ? _c : "", previousShouldInclude, compiledSkipInclude); | ||
fieldNode.__internalShouldInclude = joinShouldIncludeCompilations(fieldNode.__internalShouldInclude ?? "", previousShouldInclude, compiledSkipInclude); | ||
} | ||
@@ -179,4 +178,3 @@ /** | ||
function augmentFieldNodeTree(compilationContext, rootFieldNode, parentResponsePath) { | ||
var _a, _b; | ||
for (const selection of (_b = (_a = rootFieldNode.selectionSet) === null || _a === void 0 ? void 0 : _a.selections) !== null && _b !== void 0 ? _b : []) { | ||
for (const selection of rootFieldNode.selectionSet?.selections ?? []) { | ||
handle(rootFieldNode, selection, false, parentResponsePath); | ||
@@ -189,3 +187,2 @@ } | ||
function handle(parentFieldNode, selection, comesFromFragmentSpread = false, parentResponsePath) { | ||
var _a, _b, _c, _d, _e, _f, _g, _h; | ||
switch (selection.kind) { | ||
@@ -198,7 +195,7 @@ case language_1.Kind.FIELD: { | ||
if (!comesFromFragmentSpread) { | ||
if (!jitFieldNode.__internalShouldIncludePath) | ||
jitFieldNode.__internalShouldIncludePath = {}; | ||
if (compilationContext.options.useExperimentalPathBasedSkipInclude) { | ||
if (!jitFieldNode.__internalShouldIncludePath) | ||
jitFieldNode.__internalShouldIncludePath = {}; | ||
jitFieldNode.__internalShouldIncludePath[currentPath] = | ||
joinShouldIncludeCompilations((_b = (_a = parentFieldNode.__internalShouldIncludePath) === null || _a === void 0 ? void 0 : _a[parentResponsePath]) !== null && _b !== void 0 ? _b : "", (_d = (_c = jitFieldNode.__internalShouldIncludePath) === null || _c === void 0 ? void 0 : _c[currentPath]) !== null && _d !== void 0 ? _d : ""); | ||
joinShouldIncludeCompilations(parentFieldNode.__internalShouldIncludePath?.[parentResponsePath] ?? "", jitFieldNode.__internalShouldIncludePath?.[currentPath] ?? ""); | ||
} | ||
@@ -208,7 +205,7 @@ else { | ||
jitFieldNode.__internalShouldInclude = | ||
joinShouldIncludeCompilations((_e = parentFieldNode.__internalShouldInclude) !== null && _e !== void 0 ? _e : "", (_f = jitFieldNode.__internalShouldInclude) !== null && _f !== void 0 ? _f : ""); | ||
joinShouldIncludeCompilations(parentFieldNode.__internalShouldInclude ?? "", jitFieldNode.__internalShouldInclude ?? ""); | ||
} | ||
} | ||
// go further down the query tree | ||
for (const selection of (_h = (_g = jitFieldNode.selectionSet) === null || _g === void 0 ? void 0 : _g.selections) !== null && _h !== void 0 ? _h : []) { | ||
for (const selection of jitFieldNode.selectionSet?.selections ?? []) { | ||
handle(jitFieldNode, selection, false, currentPath); | ||
@@ -317,5 +314,4 @@ } | ||
function compileSkipIncludeDirectiveValues(compilationContext, node) { | ||
var _a, _b; | ||
const skipDirective = (_a = node.directives) === null || _a === void 0 ? void 0 : _a.find((it) => it.name.value === graphql_1.GraphQLSkipDirective.name); | ||
const includeDirective = (_b = node.directives) === null || _b === void 0 ? void 0 : _b.find((it) => it.name.value === graphql_1.GraphQLIncludeDirective.name); | ||
const skipDirective = node.directives?.find((it) => it.name.value === graphql_1.GraphQLSkipDirective.name); | ||
const includeDirective = node.directives?.find((it) => it.name.value === graphql_1.GraphQLIncludeDirective.name); | ||
const skipValue = skipDirective | ||
@@ -342,4 +338,3 @@ ? compileSkipIncludeDirective(compilationContext, skipDirective) | ||
function compileSkipIncludeDirective(compilationContext, directive) { | ||
var _a; | ||
const ifNode = (_a = directive.arguments) === null || _a === void 0 ? void 0 : _a.find((it) => it.name.value === "if"); | ||
const ifNode = directive.arguments?.find((it) => it.name.value === "if"); | ||
if (ifNode == null) { | ||
@@ -368,4 +363,3 @@ throw new graphql_1.GraphQLError(`Directive '${directive.name.value}' is missing required arguments: 'if'`, (0, compat_1.getGraphQLErrorOptions)([directive])); | ||
function validateSkipIncludeVariableType(compilationContext, variable) { | ||
var _a; | ||
const variableDefinition = (_a = compilationContext.operation.variableDefinitions) === null || _a === void 0 ? void 0 : _a.find((it) => it.variable.name.value === variable.name.value); | ||
const variableDefinition = compilationContext.operation.variableDefinitions?.find((it) => it.variable.name.value === variable.name.value); | ||
if (variableDefinition == null) { | ||
@@ -372,0 +366,0 @@ throw new graphql_1.GraphQLError(`Variable '${variable.name.value}' is not defined`, (0, compat_1.getGraphQLErrorOptions)([variable])); |
@@ -57,3 +57,10 @@ "use strict"; | ||
try { | ||
const options = Object.assign({ disablingCapturingStackErrors: false, customJSONSerializer: false, disableLeafSerialization: false, customSerializers: {}, useExperimentalPathBasedSkipInclude: false }, partialOptions); | ||
const options = { | ||
disablingCapturingStackErrors: false, | ||
customJSONSerializer: false, | ||
disableLeafSerialization: false, | ||
customSerializers: {}, | ||
useExperimentalPathBasedSkipInclude: false, | ||
...partialOptions | ||
}; | ||
// If a valid context cannot be created due to incorrect arguments, | ||
@@ -463,3 +470,3 @@ // a "Response" with only errors is returned. | ||
? fieldNodes | ||
.map((it) => { var _a; return (_a = it.__internalShouldIncludePath) === null || _a === void 0 ? void 0 : _a[serializedResponsePath]; }) | ||
.map((it) => it.__internalShouldIncludePath?.[serializedResponsePath]) | ||
.filter((it) => it) | ||
@@ -801,3 +808,3 @@ .join(" || ") || /* if(true) - default */ "true" | ||
function createSubCompilationContext(context) { | ||
return Object.assign(Object.assign({}, context), { deferred: [] }); | ||
return { ...context, deferred: [] }; | ||
} | ||
@@ -1071,3 +1078,3 @@ function isPromise(value) { | ||
try { | ||
const eventStream = await (subscriber === null || subscriber === void 0 ? void 0 : subscriber(executionContext.rootValue, executionContext.variables, executionContext.context, resolveInfo)); | ||
const eventStream = await subscriber?.(executionContext.rootValue, executionContext.variables, executionContext.context, resolveInfo); | ||
if (eventStream instanceof Error) { | ||
@@ -1074,0 +1081,0 @@ throw eventStream; |
@@ -1,2 +0,2 @@ | ||
import { JSONSchema6 } from "json-schema"; | ||
import { Schema } from "fast-json-stringify"; | ||
import { CompilationContext } from "./execution"; | ||
@@ -9,2 +9,2 @@ /** | ||
*/ | ||
export declare function queryToJSONSchema(compilationContext: CompilationContext): JSONSchema6; | ||
export declare function queryToJSONSchema(compilationContext: CompilationContext): Schema; |
@@ -42,4 +42,5 @@ "use strict"; | ||
data: { | ||
type: ["object", "null"], | ||
properties: fieldProperties | ||
type: "object", | ||
properties: fieldProperties, | ||
nullable: true | ||
}, | ||
@@ -96,4 +97,5 @@ errors: { | ||
return { | ||
type: ["object", "null"], | ||
properties | ||
type: "object", | ||
properties, | ||
nullable: true | ||
}; | ||
@@ -103,4 +105,5 @@ } | ||
return { | ||
type: ["array", "null"], | ||
items: transformNode(compilationContext, fieldNodes, type.ofType) | ||
type: "array", | ||
items: transformNode(compilationContext, fieldNodes, type.ofType), | ||
nullable: true | ||
}; | ||
@@ -110,11 +113,9 @@ } | ||
const nullable = transformNode(compilationContext, fieldNodes, type.ofType); | ||
if (nullable.type && Array.isArray(nullable.type)) { | ||
const nonNullable = nullable.type.filter((x) => x !== "null"); | ||
return Object.assign(Object.assign({}, nullable), { type: nonNullable.length === 1 ? nonNullable[0] : nonNullable }); | ||
} | ||
return {}; | ||
nullable.nullable = false; | ||
return nullable; | ||
} | ||
if ((0, graphql_1.isEnumType)(type)) { | ||
return { | ||
type: ["string", "null"] | ||
type: "string", | ||
nullable: true | ||
}; | ||
@@ -125,6 +126,7 @@ } | ||
if (!jsonSchemaType) { | ||
return {}; | ||
throw new Error(`Got unexpected PRIMITIVES type: ${type.name}`); | ||
} | ||
return { | ||
type: [jsonSchemaType, "null"] | ||
type: jsonSchemaType, | ||
nullable: true | ||
}; | ||
@@ -135,7 +137,11 @@ } | ||
const jsonSchema = transformNode(compilationContext, fieldNodes, t); | ||
res.properties = Object.assign(Object.assign({}, res.properties), jsonSchema.properties); | ||
res.properties = { | ||
...res.properties, | ||
...jsonSchema.properties | ||
}; | ||
return res; | ||
}, { | ||
type: ["object", "null"], | ||
properties: {} | ||
type: "object", | ||
properties: {}, | ||
nullable: true | ||
}); | ||
@@ -142,0 +148,0 @@ } |
@@ -14,3 +14,6 @@ "use strict"; | ||
function createLeafField(props) { | ||
return Object.assign({ [LeafFieldSymbol]: true }, props); | ||
return { | ||
[LeafFieldSymbol]: true, | ||
...props | ||
}; | ||
} | ||
@@ -218,3 +221,6 @@ function isLeafField(obj) { | ||
if (isLeafField(srcValue)) { | ||
return Object.assign(Object.assign({}, objValue), srcValue); | ||
return { | ||
...objValue, | ||
...srcValue | ||
}; | ||
} | ||
@@ -221,0 +227,0 @@ return objValue; |
@@ -18,3 +18,3 @@ "use strict"; | ||
function createSubCompilationContext(context) { | ||
return Object.assign({}, context); | ||
return { ...context }; | ||
} | ||
@@ -21,0 +21,0 @@ function compileVariableParsing(schema, varDefNodes) { |
{ | ||
"name": "graphql-jit", | ||
"version": "0.8.2", | ||
"version": "0.8.3", | ||
"description": "GraphQL JIT Compiler to JS", | ||
@@ -58,3 +58,3 @@ "main": "dist/index.js", | ||
"@types/benchmark": "^1.0.31", | ||
"@types/jest": "^27.0.3", | ||
"@types/jest": "^29.5.2", | ||
"@types/json-schema": "^7.0.1", | ||
@@ -77,6 +77,6 @@ "@types/lodash.memoize": "^4.1.6", | ||
"graphql": "^16.0.0", | ||
"jest": "^27.4.3", | ||
"jest": "^29.5.0", | ||
"lint-staged": "^8.1.5", | ||
"prettier": "^2.4.1", | ||
"ts-jest": "^27.0.7", | ||
"ts-jest": "^29.1.0", | ||
"ts-node": "^8.0.3", | ||
@@ -86,6 +86,5 @@ "typescript": "^4.4.4" | ||
"dependencies": { | ||
"@graphql-typed-document-node/core": "^3.1.1", | ||
"fast-json-stringify": "^1.21.0", | ||
"@graphql-typed-document-node/core": "^3.2.0", | ||
"fast-json-stringify": "^5.7.0", | ||
"generate-function": "^2.3.1", | ||
"json-schema": "^0.4.0", | ||
"lodash.memoize": "^4.1.2", | ||
@@ -92,0 +91,0 @@ "lodash.merge": "4.6.2", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7
3516
233757
+ Added@fastify/merge-json-schemas@0.1.1(transitive)
+ Addedajv@8.17.1(transitive)
+ Addedajv-formats@3.0.1(transitive)
+ Addedfast-json-stringify@5.16.1(transitive)
+ Addedfast-uri@2.4.03.0.3(transitive)
+ Addedjson-schema-ref-resolver@1.0.1(transitive)
+ Addedjson-schema-traverse@1.0.0(transitive)
+ Addedrequire-from-string@2.0.2(transitive)
+ Addedrfdc@1.4.1(transitive)
- Removedjson-schema@^0.4.0
- Removedajv@6.12.6(transitive)
- Removeddeepmerge@4.3.1(transitive)
- Removedfast-json-stable-stringify@2.1.0(transitive)
- Removedfast-json-stringify@1.21.0(transitive)
- Removedjson-schema@0.4.0(transitive)
- Removedjson-schema-traverse@0.4.1(transitive)
- Removedpunycode@2.3.1(transitive)
- Removedstring-similarity@4.0.4(transitive)
- Removeduri-js@4.4.1(transitive)
Updatedfast-json-stringify@^5.7.0