Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function executeNode(
context: ExecutionContext,
node: PlanNode,
results: ResultMap | ResultMap[],
path: ResponsePath,
captureTraces: boolean,
): Promise {
if (!results) {
// XXX I don't understand `results` threading well enough to understand when this happens
// and if this corresponds to a real query plan node that should be reported or not.
//
// This may be if running something like `query { fooOrNullFromServiceA {
// somethingFromServiceB } }` and the first field is null, then we don't bother to run the
// inner field at all.
return new Trace.QueryPlanNode();
}
switch (node.kind) {
case 'Sequence': {
const traceNode = new Trace.QueryPlanNode.SequenceNode();
for (const childNode of node.nodes) {
const childTraceNode = await executeNode(
context,
childNode,
results,
path,
captureTraces,
);
traceNode.nodes.push(childTraceNode!);
}
return new Trace.QueryPlanNode({ sequence: traceNode });
const traceNode = new Trace.QueryPlanNode.FetchNode({
serviceName: node.serviceName,
// executeFetch will fill in the other fields if desired.
});
try {
await executeFetch(
context,
node,
results,
path,
captureTraces ? traceNode : null,
);
} catch (error) {
context.errors.push(error);
}
return new Trace.QueryPlanNode({ fetch: traceNode });
}
}
}