Skip to content
This repository has been archived by the owner on Jul 6, 2020. It is now read-only.

Commit

Permalink
Remove additional map for for-loop
Browse files Browse the repository at this point in the history
  • Loading branch information
kitten committed Dec 3, 2019
1 parent a6fa0a2 commit abfd97a
Showing 1 changed file with 26 additions and 25 deletions.
51 changes: 26 additions & 25 deletions src/populateExchange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,10 @@ export const extractSelectionsFromQuery = ({
visitWithTypeInfo(typeInfo, {
Field: node => {
if (node.selectionSet) {
const type = getTypeName(typeInfo);
selections.push({ selections: node.selectionSet, type });
selections.push({
selections: node.selectionSet,
type: getTypeName(typeInfo),
});
}
},
FragmentDefinition: node => {
Expand Down Expand Up @@ -232,29 +234,28 @@ export const addFragmentsToQuery = ({
return p;
}

p.push(
...typeFragments[t.name].map(({ fragment }) => {
const fragmentName = getName(fragment);
const usedFragments = getUsedFragments(fragment);

// Add used fragment for insertion at Document node
for (let i = 0, l = usedFragments.length; i < l; i++) {
const name = usedFragments[i];
requiredUserFragments[name] = userFragments[name];
}

// Add fragment for insertion at Document node
additionalFragments[fragmentName] = fragment;

return {
kind: 'FragmentSpread',
name: {
kind: 'Name',
value: fragmentName,
},
} as const;
})
);
for (let i = 0, l = typeFrags.length; i < l; i++) {
const { fragment } = typeFrags[i];
const fragmentName = getName(fragment);
const usedFragments = getUsedFragments(fragment);

// Add used fragment for insertion at Document node
for (let j = 0, l = usedFragments.length; j < l; j++) {
const name = usedFragments[j];
requiredUserFragments[name] = userFragments[name];
}

// Add fragment for insertion at Document node
additionalFragments[fragmentName] = fragment;

p.push({
kind: 'FragmentSpread',
name: {
kind: 'Name',
value: fragmentName,
},
});
}

return p;
}, [] as FragmentSpreadNode[]);
Expand Down

0 comments on commit abfd97a

Please sign in to comment.