node_modules.apollo-codegen.src.compiler.visitors.collectFragmentsReferenced.ts Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of apollo-client-maven-plugin Show documentation
Show all versions of apollo-client-maven-plugin Show documentation
Maven plugin for generating graphql clients
import { SelectionSet, Fragment } from '../';
export function collectFragmentsReferenced(
selectionSet: SelectionSet,
fragments: { [fragmentName: string]: Fragment },
fragmentsReferenced: Set = new Set()
): Set {
for (const selection of selectionSet.selections) {
switch (selection.kind) {
case 'FragmentSpread':
fragmentsReferenced.add(selection.fragmentName);
const fragment = fragments[selection.fragmentName];
if (!fragment) {
throw new Error(`Cannot find fragment "${selection.fragmentName}"`);
}
collectFragmentsReferenced(fragment.selectionSet, fragments, fragmentsReferenced);
break;
case 'Field':
case 'TypeCondition':
case 'BooleanCondition':
if (selection.selectionSet) {
collectFragmentsReferenced(selection.selectionSet, fragments, fragmentsReferenced);
}
break;
}
}
return fragmentsReferenced;
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy