How to use the apollo-codegen-core/lib/compiler.compileToIR function in apollo-codegen-core

To help you get started, we’ve selected a few apollo-codegen-core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github apollographql / apollo-tooling / packages / apollo-codegen-flow / src / __tests__ / codeGeneration.ts View on Github external
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();
  });
});
github apollographql / apollo-tooling / packages / apollo-codegen-typescript / src / __tests__ / codeGeneration.ts View on Github external
function compile(
  source: string,
  options: CompilerOptions = {
    mergeInFieldsFromFragmentSpreads: true,
    addTypename: true
  }
): CompilerContext {
  const document = parse(source);
  return compileToIR(schema, document, options);
}
github apollographql / apollo-tooling / packages / apollo-codegen-swift / src / __tests__ / codeGeneration.ts View on Github external
function compile(
    source: string,
    options: CompilerOptions = { mergeInFieldsFromFragmentSpreads: true }
  ): CompilerContext {
    const document = parse(source);
    const context = compileToIR(schema, document, options);
    generator.context = context;
    return context;
  }
github apollographql / apollo-tooling / packages / apollo-codegen-typescript / src / __tests__ / codeGeneration.ts View on Github external
function compileMisc(
  source: string,
  options: CompilerOptions = {
    mergeInFieldsFromFragmentSpreads: true,
    addTypename: true
  }
): CompilerContext {
  const document = parse(source);
  return compileToIR(miscSchema, document, options);
}
github apollographql / apollo-tooling / packages / apollo-codegen-flow / src / __tests__ / codeGeneration.ts View on Github external
function compile(
  source: string,
  options: FlowCompilerOptions = {
    mergeInFieldsFromFragmentSpreads: true,
    useFlowExactObjects: false,
    useReadOnlyTypes: false,
    addTypename: true
  }
): CompilerContext {
  const document = parse(source);
  return compileToIR(schema, document, options);
}
github apollographql / apollo-tooling / packages / apollo / src / generate.ts View on Github external
);

    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);
        }
github apollographql / apollo-tooling / packages / apollo / src / generate.ts View on Github external
};
      });

      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);
        }