Skip to content

Remove undefined entities when executing Fetch of query plan #612

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Mar 31, 2021
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions gateway-js/src/executeQueryPlan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
getResponseName
} from '@apollo/query-planner';
import { deepMerge } from './utilities/deepMerge';
import { isNotNullOrUndefined } from '@apollographql/apollo-tools';

export type ServiceMap = {
[serviceName: string]: GraphQLDataSource;
Expand Down Expand Up @@ -192,7 +193,7 @@ async function executeNode<TContext>(
async function executeFetch<TContext>(
context: ExecutionContext<TContext>,
fetch: FetchNode,
results: ResultMap | ResultMap[],
results: ResultMap | (ResultMap | null | undefined)[],
_path: ResponsePath,
traceNode: Trace.QueryPlanNode.FetchNode | null,
): Promise<void> {
Expand All @@ -202,7 +203,14 @@ async function executeFetch<TContext>(
throw new Error(`Couldn't find service with name "${fetch.serviceName}"`);
}

const entities = Array.isArray(results) ? results : [results];
let entities: ResultMap[];
if (Array.isArray(results)) {
// Remove null or undefined entities from the list
entities = results.filter(isNotNullOrUndefined);
} else {
entities = [results];
}

if (entities.length < 1) return;

let variables = Object.create(null);
Expand Down