Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const fragmentNameToFile: FragmentNameToFile = options.documents.reduce((prev: FragmentNameToFile, documentRecord) => {
const fragments: FragmentDefinitionNode[] = documentRecord.content.definitions.filter(d => d.kind === Kind.FRAGMENT_DEFINITION) as FragmentDefinitionNode[];
if (fragments.length > 0) {
for (const fragment of fragments) {
const schemaType = schemaObject.getType(fragment.typeCondition.name.value);
if (!schemaType) {
throw new Error(`Fragment "${fragment.name.value}" is set on non-existing type "${fragment.typeCondition.name.value}"!`);
}
const possibleTypes = getPossibleTypes(schemaObject, schemaType);
const fragmentSuffix = options.config.dedupeOperationSuffix && fragment.name.value.toLowerCase().endsWith('fragment') ? '' : 'Fragment';
const filePath = appendExtensionToFilePath(documentRecord.filePath, extension);
const importsNames = getAllFragmentSubTypes(
possibleTypes.map(t => t.name),
fragment.name.value,
fragmentSuffix
);
if (prev[fragment.name.value]) {
duplicateFragmentNames.push(fragment.name.value);
}
prev[fragment.name.value] = { filePath, importsNames, onType: fragment.typeCondition.name.value, node: fragment };
}
}