From 015e3d3ed9fbb8ec1866c136103034b5ef5ff2af Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Fri, 1 Dec 2017 16:47:54 +0100 Subject: [PATCH] Tiny refactor --- client/coral-framework/graphql/reduceDocument.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/client/coral-framework/graphql/reduceDocument.js b/client/coral-framework/graphql/reduceDocument.js index 927379ff2..a713f8078 100644 --- a/client/coral-framework/graphql/reduceDocument.js +++ b/client/coral-framework/graphql/reduceDocument.js @@ -76,7 +76,7 @@ export function mergeSelectionSets(a, b) { }; } -function getFragment(name, execContext) { +function getFragmentOrDie(name, execContext) { const { rawFragmentMap, fragmentMap, @@ -125,14 +125,10 @@ function getTransformedSelections(definition, path, gqlType, execContext) { return o; } - const fragment = getFragment(sel.name.value, execContext); - - if (!fragment) { - throw new Error(`fragment ${fragment.name.value} does not exist`); - } - + const fragment = getFragmentOrDie(sel.name.value, execContext); const typeCondition = fragment.typeCondition.name.value; + // Turn NamedFragment into an InlineFragment. if (gqlType !== typeCondition) { const node = { ...fragment, @@ -150,6 +146,7 @@ function getTransformedSelections(definition, path, gqlType, execContext) { return o; } + // Merge NamedFragment directly into selections. const fragmentSelections = fragment.selectionSet.selections; fragmentSelections.forEach((s) => {