How to use the graphql-config.getGraphQLConfig 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 apollographql / eslint-plugin-graphql / src / index.js View on Github external
const cacheHit = schemaCache[JSON.stringify(optionGroup)];
  if (cacheHit && env !== "literal") {
    return cacheHit;
  }

  // Validate and unpack schema
  let schema;
  if (schemaJson) {
    schema = initSchema(schemaJson);
  } else if (schemaJsonFilepath) {
    schema = initSchemaFromFile(schemaJsonFilepath);
  } else if (schemaString) {
    schema = initSchemaFromString(schemaString);
  } else {
    try {
      const config = getGraphQLConfig(path.dirname(context.getFilename()));
      let projectConfig;
      if (projectName) {
        projectConfig = config.getProjects()[projectName];
        if (!projectConfig) {
          throw new Error(
            `Project with name "${projectName}" not found in ${config.configPath}.`
          );
        }
      } else {
        projectConfig = config.getConfigForFile(context.getFilename());
      }
      if (projectConfig) {
        const key = `${config.configPath}[${projectConfig.projectName}]`;
        schema = projectCache[key];
        if (!schema) {
          schema = projectConfig.getSchema();
github Urigo / graphql-cli / src / index.ts View on Github external
let config: GraphQLProjectConfig | undefined
        while (!config) {
          try {
            config = argv['project']
              ? getGraphQLProjectConfig(process.cwd(), argv['project'])
              : (getGraphQLProjectConfig(process.cwd()) as GraphQLProjectConfig)

            config.config = resolveEnvsInValues(config.config, process.env)
            config = await patchGraphcoolEndpointsToConfig(
              config,
              process.cwd(),
            )
            config = await patchPrismaEndpointsToConfig(config, process.cwd())
            config = await patchOpenApiEndpointsToConfig(config)
          } catch (error) {
            const config: GraphQLConfig = getGraphQLConfig(process.cwd())
            const projectNames = Object.keys(config.getProjects() || {})
            if (projectNames) {
              if (error.message.includes('multiproject')) {
                console.log(chalk.yellow('No project name specified'))
              } else if (error.message.includes('not a valid project name')) {
                console.log(chalk.yellow('Invalid project name specified'))
              }
              const { projectName } = await inquirer.prompt<{
                projectName: string
              }>({
                type: 'list',
                name: 'projectName',
                choices: projectNames,
                message: 'Select a project:',
              })
              argv['project'] = projectName
github coralproject / talk / scripts / generateSchemaTypes.js View on Github external
async function main() {
  const config = getGraphQLConfig(__dirname);
  const projects = config.getProjects();

  const files = [
    {
      name: "tenant",
      fileName: path.join(
        __dirname,
        "../src/core/server/graph/tenant/schema/__generated__/types.ts"
      ),
      config: {
        contextType: "TenantContext",
        importStatements: [
          'import TenantContext from "coral-server/graph/tenant/context";',
          'import { Cursor } from "coral-server/models/helpers";',
        ],
        customScalarType: { Cursor: "Cursor", Time: "Date" },
github prisma-labs / vscode-graphql / ts-graphql-plugin / src / graphql-language-service-proxy.ts View on Github external
getCompletionsAtPosition(
    context: TemplateContext,
    position: ts.LineAndCharacter
  ): ts.CompletionInfo {
    try {
      const config = getGraphQLConfig();
      let projectConfig = config.getConfigForFile(context.fileName);
      if (!projectConfig) {
        projectConfig = this.patchProjectConfig(config);
      }
      const schema = projectConfig.getSchema();
      const completions = getAutocompleteSuggestions(
        schema,
        context.text,
        position
      );
      const completionInfo = {
        isGlobalCompletion: false,
        isMemberCompletion: false,
        isNewIdentifierLocation: false,
        entries: completions.map(completion => {
          return {
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;
      }
github graphql / graphiql / packages / graphql-language-service-server / src / MessageProcessor.js View on Github external
textDocumentSync: 1,
        hoverProvider: true,
      },
    };

    const rootPath = dirname(
      findGraphQLConfigFile(configDir ? configDir.trim() : params.rootPath)
    );
    if (!rootPath) {
      throw new Error(
        '`--configDir` option or `rootPath` argument is required.'
      );
    }

    this._graphQLCache = await getGraphQLCache(rootPath);
    const config = getGraphQLConfig(rootPath);
    if (this._watchmanClient) {
      this._subcribeWatchman(config, this._watchmanClient);
    }
    this._languageService = new GraphQLLanguageService(this._graphQLCache);

    if (!serverCapabilities) {
      throw new Error('GraphQL Language Server is not initialized.');
    }

    this._isInitialized = true;

    this._logger.log(
      JSON.stringify({
        type: 'usage',
        messageType: 'initialize',
      })
github aws-amplify / amplify-cli / packages / amplify-frontend-android / lib / frontend-config-creator.js View on Github external
function deleteAmplifyConfig(context) {
  const { srcDirPath, projectPath } = getSrcDir(context);
  const targetFilePath = path.join(srcDirPath, constants.amplifyConfigFilename);
  if (fs.existsSync(targetFilePath)) {
    fs.removeSync(targetFilePath);
  }

  if (!fs.existsSync(path.join(projectPath, '.graphqlconfig.yml'))) return;

  const gqlConfig = graphQLConfig.getGraphQLConfig(projectPath);
  if (gqlConfig && gqlConfig.config) {
    const { projects } = gqlConfig.config;
    Object.keys(projects).forEach(project => {
      const { codeGenTarget, docsFilePath } = projects[project].extensions.amplify;
      fileNames.forEach(filename => {
        const file = path.join(projectPath, docsFilePath, `${filename}.${FILE_EXTENSION_MAP[codeGenTarget] || 'graphql'}`);
        if (fs.existsSync(file)) fs.removeSync(file);
      });
    });
  }
}
github graphql / graphiql / packages / graphql-language-service-server / src / GraphQLCache.js View on Github external
export async function getGraphQLCache(
  configDir: Uri
): Promise {
  const graphQLConfig = await getGraphQLConfig(configDir);
  return new GraphQLCache(configDir, graphQLConfig);
}
github prisma-labs / vscode-graphql / src / client / graphql-content-provider.ts View on Github external
this.sourceHelper = new SourceHelper(this.outputChannel);
    this.panel = panel;
    this.env = env;

    try {
      const rootDir = workspace.getWorkspaceFolder(Uri.file(literal.uri));
      if (!rootDir) {
        this.outputChannel.appendLine(
          `Error: this file is outside the workspace.`
        );
        this.html = "Error: this file is outside the workspace.";
        this.update(this.uri);
        this.updatePanel();
        return;
      } else {
        const config = getGraphQLConfig(rootDir!.uri.fsPath);
        let projectConfig = config.getConfigForFile(literal.uri);
        if (!projectConfig) {
          projectConfig = this.patchProjectConfig(
            config
          ) as GraphQLProjectConfig;
        }

        if (!projectConfig!.endpointsExtension) {
          this.outputChannel.appendLine(
            `Error: endpoint data missing from graphql config`
          );
          this.html = "Error: endpoint data missing from graphql config";
          this.update(this.uri);
          this.updatePanel();
          return;
        }