How to use the apollo-codegen-core/lib/localfs.fs.writeFileSync 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 / src / generate.ts View on Github external
writtenFiles += 1;
    }
  } else {
    let output;
    const context = compileToLegacyIR(schema, document, options);
    switch (target) {
      case "json":
        output = serializeToJSON(context);
        break;
      case "scala":
        output = generateScalaSource(context);
    }

    if (outputPath) {
      fs.writeFileSync(outputPath, output);
      writtenFiles += 1;
    } else {
      console.log(output);
    }
  }

  return writtenFiles;
}
github apollographql / apollo-tooling / packages / apollo / src / generate.ts View on Github external
fs.mkdirSync(dir);
          }
        }

        const outFilePath = path.join(dir, fileName);
        outFiles[outFilePath] = {
          output: content({ outputPath: outFilePath, globalSourcePath })
            .fileContents
        };
      });

      writeGeneratedFiles(outFiles, path.resolve("."));

      writtenFiles += Object.keys(outFiles).length;
    } else {
      fs.writeFileSync(
        outputPath,
        generatedFiles.map(o => o.content().fileContents).join("\n") +
          "\n" +
          generatedGlobalFile.fileContents
      );

      writtenFiles += 1;
    }
  } else {
    let output;
    const context = compileToLegacyIR(schema, document, options);
    switch (target) {
      case "json":
        output = serializeToJSON(context);
        break;
      case "scala":
github apollographql / apollo-tooling / packages / apollo / src / generate.ts View on Github external
const suppressSwiftMultilineStringLiterals = Boolean(
      options.suppressSwiftMultilineStringLiterals
    );

    const generator = generateSwiftSource(
      context,
      outputIndividualFiles,
      suppressSwiftMultilineStringLiterals,
      only
    );

    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) {
github apollographql / apollo-tooling / packages / apollo / src / generate.ts View on Github external
function writeGeneratedFiles(
  generatedFiles: { [fileName: string]: BasicGeneratedFile },
  outputDirectory: string,
  terminator: string = ""
) {
  for (const [fileName, generatedFile] of Object.entries(generatedFiles)) {
    fs.writeFileSync(
      path.join(outputDirectory, fileName),
      generatedFile.output.concat(terminator)
    );
  }
}
github apollographql / apollo-tooling / packages / apollo / src / generate.ts View on Github external
function writeOperationIdsMap(context: CompilerContext) {
  let operationIdsMap: { [id: string]: OperationIdsMap } = {};
  Object.keys(context.operations)
    .map(k => context.operations[k])
    .forEach(operation => {
      operationIdsMap[operation.operationId!] = {
        name: operation.operationName,
        source: operation.source
      };
    });
  fs.writeFileSync(
    context.options.operationIdsPath,
    JSON.stringify(operationIdsMap, null, 2)
  );
}