How to use the apollo-codegen-core/lib/localfs.fs.readFileSync 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 / fetch-schema.ts View on Github external
async function fromFile(
  file: string
): Promise {
  let result;
  try {
    result = fs.readFileSync(file, {
      encoding: "utf-8"
    });
  } catch (err) {
    throw new Error(`Unable to read file ${file}. ${err.message}`);
  }

  const ext = path.extname(file);

  // an actual introspectionQuery result
  if (ext === ".json") {
    const parsed = JSON.parse(result);
    const schemaData = parsed.data
      ? parsed.data.__schema
      : parsed.__schema
        ? parsed.__schema
        : parsed;
github apollographql / apollo-tooling / packages / apollo / src / config.ts View on Github external
file: string,
  defaultEndpoint: boolean,
  defaultSchema: boolean
): ApolloConfig {
  if (file.endsWith(".js")) {
    const filepath = resolve(file);
    delete require.cache[require.resolve(filepath)];
    return loadConfig(
      require(filepath),
      filepath,
      dirname(filepath),
      defaultEndpoint,
      defaultSchema
    );
  } else if (file.endsWith("package.json")) {
    const apolloKey = JSON.parse(fs.readFileSync(file).toString()).apollo;
    if (apolloKey) {
      return loadConfig(
        apolloKey,
        file,
        dirname(file),
        defaultEndpoint,
        defaultSchema
      );
    } else {
      return loadConfig(
        {},
        file,
        dirname(file),
        defaultEndpoint,
        defaultSchema
      );