Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (!config.withFragmentContainer) {
return "";
}
let queryName = doc.name.split("_")[0];
if (!queryName) {
return "";
}
const query = queryDocuments.find(query => query.name === queryName);
if (!query) {
console.warn(
`Fragment '${doc.name}' uses relay notation but no query was found.`
);
return "";
}
const queryAst = parse(GraphQLIRPrinter.print(query));
// @TODO: there might be multiple selection paths that use this fragment
// build path on generated type
const selectionPath = [];
let currentSelectionSet = null;
visit(queryAst, {
enter: (node, key, parent) => {
if (node.kind === "SelectionSet") {
currentSelectionSet = node;
if (parent.kind === "OperationDefinition") {
selectionPath.push({
type: "query",
name: parent.name.value
});
} else {
const newQueryDocuments = queryCompilerContext.documents().map(doc => ({
filePath: "optimized by relay",
content: parse(GraphQLIRPrinter.print(doc))
}));
if (compiledNodes.has(filePath)) {
let otherNode = compiledNodes.get(filePath)
this.reportError(
multipleRootQueriesError(
filePath,
nameDefMap.get(name),
otherNode && nameDefMap.get(otherNode.name)
)
)
return
}
let text = filterContextForNode(printContext.getRoot(name), printContext)
.documents()
.map(GraphQLIRPrinter.print)
.join(`\n`)
const query = {
name,
text,
originalText: nameDefMap.get(name).text,
path: filePath,
isHook: nameDefMap.get(name).isHook,
isStaticQuery: nameDefMap.get(name).isStaticQuery,
hash: nameDefMap.get(name).hash,
}
if (query.isStaticQuery) {
query.jsonName =
`sq--` +
_.kebabCase(