UNPKG

@graphql-mesh/fusion-execution

Version:
105 lines (104 loc) 5.36 kB
import { createExecutableResolverOperationNode, } from './execution.js'; import { parseAndCache, printCached } from './parseAndPrintWithCache.js'; export function serializeResolverOperationNode(resolverOperationNode) { const serializedNode = { subgraph: resolverOperationNode.subgraph, resolverOperationDocument: 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; } export function deserializeResolverOperationNode(serializedResolverOperationNode) { const resolverOperationNode = { subgraph: serializedResolverOperationNode.subgraph, resolverOperationDocument: 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; } export function deserializeResolverOperationNodeExecutable(serializedNode) { return createExecutableResolverOperationNode(deserializeResolverOperationNode(serializedNode), 0); } export function serializeExecutableResolverOperationNode(executableResolverOperationNode) { const serializedNode = { subgraph: executableResolverOperationNode.subgraph, resolverOperationDocument: 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; }