@graphql-mesh/fusion-execution
Version:
Runtime for Fusion Supergraph
112 lines (111 loc) • 6.04 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.serializeExecutableResolverOperationNode = exports.deserializeResolverOperationNodeExecutable = exports.deserializeResolverOperationNode = exports.serializeResolverOperationNode = void 0;
const execution_js_1 = require("./execution.js");
const parseAndPrintWithCache_js_1 = require("./parseAndPrintWithCache.js");
function serializeResolverOperationNode(resolverOperationNode) {
const serializedNode = {
subgraph: resolverOperationNode.subgraph,
resolverOperationDocument: (0, parseAndPrintWithCache_js_1.printCached)(resolverOperationNode.resolverOperationDocument),
};
if (resolverOperationNode.id != null) {
serializedNode.id = resolverOperationNode.id;
}
if (resolverOperationNode.resolverDependencies.length) {
serializedNode.resolverDependencies = resolverOperationNode.resolverDependencies.map(serializeResolverOperationNode);
}
if (resolverOperationNode.resolverPreDependencies.length) {
serializedNode.resolverPreDependencies = resolverOperationNode.resolverPreDependencies.map(serializeResolverOperationNode);
}
if (resolverOperationNode.resolverDependencyFieldMap.size) {
serializedNode.resolverDependencyFieldMap = Object.fromEntries([...resolverOperationNode.resolverDependencyFieldMap.entries()].map(([key, value]) => [
key,
value.map(serializeResolverOperationNode),
]));
}
if (resolverOperationNode.batch) {
serializedNode.batch = true;
}
if (resolverOperationNode.defer) {
serializedNode.defer = true;
}
return serializedNode;
}
exports.serializeResolverOperationNode = serializeResolverOperationNode;
function deserializeResolverOperationNode(serializedResolverOperationNode) {
const resolverOperationNode = {
subgraph: serializedResolverOperationNode.subgraph,
resolverOperationDocument: (0, parseAndPrintWithCache_js_1.parseAndCache)(serializedResolverOperationNode.resolverOperationDocument),
};
if (serializedResolverOperationNode.resolverDependencies) {
resolverOperationNode.resolverDependencies =
serializedResolverOperationNode.resolverDependencies.map(deserializeResolverOperationNode);
}
else {
resolverOperationNode.resolverDependencies = [];
}
if (serializedResolverOperationNode.resolverPreDependencies) {
resolverOperationNode.resolverPreDependencies =
serializedResolverOperationNode.resolverPreDependencies.map(deserializeResolverOperationNode);
}
else {
resolverOperationNode.resolverPreDependencies = [];
}
if (serializedResolverOperationNode.resolverDependencyFieldMap) {
resolverOperationNode.resolverDependencyFieldMap = new Map(Object.entries(serializedResolverOperationNode.resolverDependencyFieldMap).map(([key, value]) => [key, value.map(deserializeResolverOperationNode)]));
}
else {
resolverOperationNode.resolverDependencyFieldMap = new Map();
}
if (serializedResolverOperationNode.batch) {
resolverOperationNode.batch = true;
}
if (serializedResolverOperationNode.defer) {
resolverOperationNode.defer = true;
}
return resolverOperationNode;
}
exports.deserializeResolverOperationNode = deserializeResolverOperationNode;
function deserializeResolverOperationNodeExecutable(serializedNode) {
return (0, execution_js_1.createExecutableResolverOperationNode)(deserializeResolverOperationNode(serializedNode), 0);
}
exports.deserializeResolverOperationNodeExecutable = deserializeResolverOperationNodeExecutable;
function serializeExecutableResolverOperationNode(executableResolverOperationNode) {
const serializedNode = {
subgraph: executableResolverOperationNode.subgraph,
resolverOperationDocument: (0, parseAndPrintWithCache_js_1.printCached)(executableResolverOperationNode.resolverOperationDocument),
};
if (executableResolverOperationNode.id != null) {
serializedNode.id = executableResolverOperationNode.id;
}
if (executableResolverOperationNode.resolverDependencies.length ||
executableResolverOperationNode.batchedResolverDependencies.length) {
serializedNode.resolverDependencies = [
...executableResolverOperationNode.resolverDependencies.map(serializeExecutableResolverOperationNode),
...executableResolverOperationNode.batchedResolverDependencies.map(serializeExecutableResolverOperationNode),
];
}
if (executableResolverOperationNode.resolverPreDependencies.length ||
executableResolverOperationNode.batchedPreResolverDependencies.length) {
serializedNode.resolverPreDependencies = [
...executableResolverOperationNode.resolverPreDependencies.map(serializeExecutableResolverOperationNode),
...executableResolverOperationNode.batchedPreResolverDependencies.map(serializeExecutableResolverOperationNode),
];
}
if (executableResolverOperationNode.resolverDependencyFieldMap.size ||
executableResolverOperationNode.batchedResolverDependencyFieldMap.size) {
serializedNode.resolverDependencyFieldMap = Object.fromEntries([...executableResolverOperationNode.resolverDependencyFieldMap.entries()].map(([key, value]) => [key, value.map(serializeExecutableResolverOperationNode)]));
for (const [key, value] of executableResolverOperationNode.batchedResolverDependencyFieldMap) {
serializedNode.resolverDependencyFieldMap[key] ||= [];
serializedNode.resolverDependencyFieldMap[key].push(...value.map(serializeExecutableResolverOperationNode));
}
}
if (executableResolverOperationNode.batch) {
serializedNode.batch = true;
}
if (executableResolverOperationNode.defer) {
serializedNode.defer = true;
}
return serializedNode;
}
exports.serializeExecutableResolverOperationNode = serializeExecutableResolverOperationNode;
;