How to use the graphql-config.ConfigNotFoundError function in graphql-config

To help you get started, we’ve selected a few graphql-config 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 otissv / remodule / node_modules / eslint-plugin-graphql / lib / index.js View on Github external
// Validate and unpack schema

  var schema = void 0;
  if (schemaJson) {
    schema = initSchema(schemaJson);
  } else if (schemaJsonFilepath) {
    schema = initSchemaFromFile(schemaJsonFilepath);
  } else if (schemaString) {
    schema = initSchemaFromString(schemaString);
  } else {
    try {
      var config = (0, _graphqlConfig.getGraphQLProjectConfig)('.', projectName);
      schema = config.getSchema();
    } catch (e) {
      if (e instanceof _graphqlConfig.ConfigNotFoundError) {
        throw new Error('Must provide .graphqlconfig file or pass in `schemaJson` option ' + 'with schema object or `schemaJsonFilepath` with absolute path to the json file.');
      }
      throw e;
    }
  }

  // Validate env
  if (env && env !== 'lokka' && env !== 'relay' && env !== 'apollo' && env !== 'literal') {
    throw new Error('Invalid option for env, only `apollo`, `lokka`, `relay`, and `literal` supported.');
  }

  // Validate tagName and set default
  var tagName = void 0;
  if (tagNameOption) {
    tagName = tagNameOption;
  } else if (env === 'relay') {
github aws-amplify / amplify-cli / packages / amplify-codegen / src / codegen-config / AmplifyCodeGenConfig.js View on Github external
constructor(context, withoutInit = false) {
    try {
      this.gqlConfig = graphQLConfig.getGraphQLConfig();
      this.fixOldConfig();
    } catch (e) {
      if (e instanceof graphQLConfig.ConfigNotFoundError) {
        const { amplify } = context;
        let projectRoot;
        if (!withoutInit) {
          projectRoot = amplify.getEnvInfo().projectPath || process.cwd();
        } else {
          projectRoot = process.cwd();
        }
        const configPath = join(projectRoot, '.graphqlconfig.yml');
        this.gqlConfig = new graphQLConfig.GraphQLConfig(null, configPath);
        this.gqlConfig.config = {};
      } else {
        throw e;
      }
    }
  }
  static isValidAmplifyProject(project) {