Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const documentAsts = documents.reduce((prev, v) => {
return [...prev, ...v.content.definitions];
}, [] as DefinitionNode[]);
const relayDocuments = RelayParser.transform(adjustedSchema, documentAsts);
const fragmentCompilerContext = new GraphQLCompilerContext(adjustedSchema).addAll(relayDocuments);
const fragmentDocuments = fragmentCompilerContext
.applyTransforms([ApplyFragmentArgumentTransform.transform, FlattenTransform.transformWithOptions({ flattenAbstractTypes: false }), SkipRedundantNodesTransform.transform])
.documents()
.filter(doc => doc.kind === 'Fragment');
const queryCompilerContext = new GraphQLCompilerContext(adjustedSchema)
.addAll(relayDocuments)
.applyTransforms([ApplyFragmentArgumentTransform.transform, InlineFragmentsTransform.transform, FlattenTransform.transformWithOptions({ flattenAbstractTypes: false }), SkipRedundantNodesTransform.transform]);
const newQueryDocuments = queryCompilerContext.documents().map(doc => ({
filePath: 'optimized by relay',
content: parse(print(adjustedSchema, doc)),
}));
const newDocuments = [
...fragmentDocuments.map(doc => ({
filePath: 'optimized by relay',
content: parse(print(adjustedSchema, doc)),
})),
...newQueryDocuments,
];
documents.splice(0, documents.length);
documents.push(...newDocuments);
).addAll(relayDocuments);
const fragmentDocuments = fragmentCompilerContext
.applyTransforms([
RelayApplyFragmentArgumentTransform.transform,
FlattenTransform.transformWithOptions({ flattenAbstractTypes: false }),
SkipRedundantNodesTransform.transform
])
.documents()
.filter(doc => doc.kind === "Fragment");
const queryCompilerContext = new GraphQLCompilerContext(adjustedSchema)
.addAll(relayDocuments)
.applyTransforms([
RelayApplyFragmentArgumentTransform.transform,
InlineFragmentsTransform.transform,
FlattenTransform.transformWithOptions({ flattenAbstractTypes: false }),
SkipRedundantNodesTransform.transform
]);
const newQueryDocuments = queryCompilerContext.documents().map(doc => ({
filePath: "optimized by relay",
content: parse(GraphQLIRPrinter.print(doc))
}));
const newDocuments = [
...fragmentDocuments.map(doc => ({
filePath: "optimized by relay",
content: parse(GraphQLIRPrinter.print(doc))
})),
...newQueryDocuments
];