Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
test("handles multiline graphql comments", () => {
const miscSchema = loadSchema(
require.resolve("../../../../__fixtures__/misc/schema.json")
);
const document = parse(`
query CustomScalar {
commentTest {
multiLine
}
}
`);
const output = generateSource(
compileToIR(miscSchema, document, {
mergeInFieldsFromFragmentSpreads: true,
addTypename: true
})
);
expect(output).toMatchSnapshot();
});
});
function compile(
source: string,
options: CompilerOptions = {
mergeInFieldsFromFragmentSpreads: true,
addTypename: true
}
): CompilerContext {
const document = parse(source);
return compileToIR(schema, document, options);
}
function compile(
source: string,
options: CompilerOptions = { mergeInFieldsFromFragmentSpreads: true }
): CompilerContext {
const document = parse(source);
const context = compileToIR(schema, document, options);
generator.context = context;
return context;
}
function compileMisc(
source: string,
options: CompilerOptions = {
mergeInFieldsFromFragmentSpreads: true,
addTypename: true
}
): CompilerContext {
const document = parse(source);
return compileToIR(miscSchema, document, options);
}
function compile(
source: string,
options: FlowCompilerOptions = {
mergeInFieldsFromFragmentSpreads: true,
useFlowExactObjects: false,
useReadOnlyTypes: false,
addTypename: true
}
): CompilerContext {
const document = parse(source);
return compileToIR(schema, document, options);
}
);
if (outputIndividualFiles) {
writeGeneratedFiles(generator.generatedFiles, outputPath, "\n");
writtenFiles += Object.keys(generator.generatedFiles).length;
} else {
fs.writeFileSync(outputPath, generator.output.concat("\n"));
writtenFiles += 1;
}
if (options.generateOperationIds) {
writeOperationIdsMap(context);
writtenFiles += 1;
}
} else if (target === "flow") {
const context = compileToIR(schema, document, options);
const { generatedFiles, common } = generateFlowSource(context);
const outFiles: {
[fileName: string]: BasicGeneratedFile;
} = {};
if (nextToSources) {
generatedFiles.forEach(({ sourcePath, fileName, content }) => {
const dir = path.join(
path.dirname(path.posix.relative(rootPath, toPath(sourcePath))),
outputPath
);
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir);
}
};
});
writeGeneratedFiles(outFiles, outputPath);
writtenFiles += Object.keys(outFiles).length;
} else {
fs.writeFileSync(
outputPath,
generatedFiles.map(o => o.content.fileContents).join("\n") + common
);
writtenFiles += 1;
}
} else if (target === "typescript" || target === "ts") {
const context = compileToIR(schema, document, options);
const generatedFiles = generateTypescriptLocalSource(context);
const generatedGlobalFile = generateTypescriptGlobalSource(context);
const outFiles: {
[fileName: string]: BasicGeneratedFile;
} = {};
if (
nextToSources ||
(fs.existsSync(outputPath) && fs.statSync(outputPath).isDirectory())
) {
if (options.globalTypesFile) {
const globalTypesDir = path.dirname(options.globalTypesFile);
if (!fs.existsSync(globalTypesDir)) {
fs.mkdirSync(globalTypesDir);
}