How to use the apollo-codegen-core/lib/errors.ToolError 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 / src / printSchema.ts View on Github external
export default async function printSchemaFromIntrospectionResult(
  schemaPath: string,
  outputPath: string,
  options?: PrinterOptions
) {
  if (!fs.existsSync(schemaPath)) {
    throw new ToolError(`Cannot find GraphQL schema file: ${schemaPath}`);
  }

  const schemaJSON = JSON.parse(fs.readFileSync(schemaPath, 'utf8'));

  if (!schemaJSON.data) {
    throw new ToolError(`No introspection query result data found in: ${schemaPath}`);
  }

  const schema = buildClientSchema(schemaJSON.data);
  const schemaIDL = printSchema(schema, options);

  if (outputPath) {
    fs.writeFileSync(outputPath, schemaIDL);
  } else {
    console.log(schemaIDL);
  }
}
github apollographql / apollo-tooling / packages / apollo-codegen / src / downloadSchema.ts View on Github external
body: JSON.stringify({ 'query': introspectionQuery }),
      agent,
    });

    result = await response.json();
  } catch (error) {
    throw new ToolError(`Error while fetching introspection query result: ${error.message}`);
  }

  if (result.errors) {
    throw new ToolError(`Errors in introspection query result: ${result.errors}`);
  }

  const schemaData = result;
  if (!schemaData.data) {
    throw new ToolError(`No introspection query result data found, server responded with: ${JSON.stringify(result)}`);
  }

  fs.writeFileSync(outputPath, JSON.stringify(schemaData, null, 2));
}
github apollographql / apollo-tooling / packages / apollo-codegen / src / cli.ts View on Github external
.fail(function(message, error) {
    handleError(error ? error : new ToolError(message));
  })
  .help()
github apollographql / apollo-tooling / packages / apollo-codegen / src / introspectSchema.ts View on Github external
export default async function introspectSchema(schemaPath: string, outputPath: string) {
  if (!fs.existsSync(schemaPath)) {
    throw new ToolError(`Cannot find GraphQL schema file: ${schemaPath}`);
  }

  const schemaContents = fs.readFileSync(schemaPath).toString();
  const result = await introspect(schemaContents);

  if (result.errors) {
    throw new ToolError(`Errors in introspection query result: ${result.errors}`);
  }

  fs.writeFileSync(outputPath, JSON.stringify(result, null, 2));
}
github apollographql / apollo-tooling / packages / apollo-codegen / src / cli.ts View on Github external
coerce: (arg) => {
          let additionalHeaders: {
            [key: string]: any
          } = {};
          for (const header of arg) {
            const separator = header.indexOf(":");
            const name = header.substring(0, separator).trim();
            const value = header.substring(separator + 1).trim();
            if (!(name && value)) {
              throw new ToolError('Headers should be specified as "Name: Value"');
            }
            additionalHeaders[name] = value;
          }
          return additionalHeaders;
        }
      },