5.0.3 • Published 7 months ago

graphql-config v5.0.3

Weekly downloads
1,626,465
License
MIT
Repository
github
Last release
7 months ago

graphql-config

Build Status npm version

The README reflects the new graphql-config protocol. Old graphql-config-parser documentation can be found here

The easiest way to configure your development environment with your GraphQL schema (supported by most tools, editors & IDEs)

Supported by...

Language Services

Editors

Tools

Did we forget a tool/editor? Please add it here.

Go to graphql-config library docs

Usage

tl;dr

Install graphql-cli and run graphql init. Answer a few simple questions and you are set up!

You can either configure your GraphQL endpoint via a configuration file .graphqlconfig (or .graphqlconfig.yaml) which should be put into the root of your project

Simplest use case

The simplest config specifies only schemaPath which is path to the file with introspection results or corresponding SDL document

{
  "schemaPath": "schema.graphql"
}

or

{
  "schemaPath": "schema.json"
}

Specifying includes/excludes files

You can specify which files are included/excluded using the corresponding options:

{
  "schemaPath": "schema.graphql",
  "includes": ["*.graphql"],
  "excludes": ["temp/**"]
}

Note: excludes and includes fields are globs that should match filename. So, just temp or temp/ won't match all files inside the directory. That's why the example uses temp/**

Specifying endpoint info

You may specify your endpoints info in .graphqlconfig which may be used by some tools. The simplest case:

{
  "schemaPath": "schema.graphql",
  "extensions": {
    "endpoints": {
      "dev": "https://example.com/graphql"
    }
  }
}

In case you need provide additional information, for example headers to authenticate your GraphQL endpoint or an endpoint for subscription, you can use expanded version:

{
  "schemaPath": "schema.graphql",
  "extensions": {
    "endpoints": {
      "dev": {
        "url": "https://example.com/graphql",
        "headers": {
          "Authorization": "Bearer ${env:AUTH_TOKEN_ENV}"
        },
        "subscription": {
          "url": "ws://example.com/graphql",
          "connectionParams": {
            "Token": "${env:YOUR_APP_TOKEN}"
          }
        }
      }
    }
  }
}

Note: do not save secure information in .graphqlconfig file. Use Environment variables for that like in the example above.

In case if you have multiple endpoints use the following syntax:

{
  "schemaPath": "schema.graphql",
  "extensions": {
    "endpoints": {
      "prod": {
        "url": "https://your-app.com/graphql",
        "subscription": {
          "url": "wss://subscriptions.graph.cool/v1/instagram"
        }
      },
      "dev": {
        "url": "http://localhost:3000/graphql",
        "subscription": {
          "url": "ws://localhost:3001"
        }
      }
    }
  }
}

Multi-project configuration (advanced)

TBD

Refer to specification use-cases for details

How it works

This project aims to be provide a unifying configuration file format to configure your GraphQL schema in your development environment.

Additional to the format specification, it provides the graphql-config library, which is used by all supported tools and editor plugins. The library reads your provided configuration and passes the actual GraphQL schema along to the tool which called it.

graphql-config API

Here are very basic examples of how to use graphql-config library.

You can find the detailed documentation here

getGraphQLProjectConfig

NOTE: if your tool works on per-file basis (e.g. editor plugin, linter, etc) use getGraphQLConfig function

getGraphQLProjectConfig should be used by tools that do not work on per-file basis

import { getGraphQLProjectConfig } from 'graphql-config'

const config = getGraphQLProjectConfig('./optionalProjectDir', 'optionalProjectName')
const schema = config.getSchema()
// use schema for your tool/plugin

getGraphQLConfig

getGraphQLConfig should be used by tools that work on per-file basis (editor plugins, linters, etc.)

import { getGraphQLConfig } from 'graphql-config'

const config = getGraphQLConfig('./optionalProjectDir')
const schema = config.getConfigForFile(filename).getSchema()
// use schema for your tool/plugin

Help & Community Slack Status

Join our Slack community if you run into issues or have questions. We love talking to you!

npm.io

@graphql-codegen/cli@jacobwgillespie/apollo-codegen@prodam/prodam-typesgraphql-cli@everything-registry/sub-chunk-1784@beardeddudes-dev/graphql-configgraphql-language-service-servergraphql-language-service-typesgraphql-language-servergraphql-language-service-interfacegraphql-typescript-definitionsgraphql-validate-fixturesgraphback-cligraphql-overridegraphql-code-generatorgraphql-cli-loadgraphql-cli-maanagraphql-codegen-bindinggraphql-codegen-cli-nuxtgraphql-config-extension-prismagraphql-config-utilitiesgraphql-config-extension-graphcoolgraphql-config-extension-openapigraphql-codegen-prisma-bindinggraphql-codegen-projects@meyer/apollo-codegen@prisma-cms/server@operato/app@sdykae/graphql-language-service-server@shopify/sewing-kit@shopify/shop-minis-cliitutor-apollo-codegen@speedlo/cli@tmcw/graphql-codegen-cli@tonyfromundefined/graphql-codegen-cli@takeshape/graphql-validate@theguild/graphql-language-service-server@test-graphql-cli/cli@test-graphql-cli/codegen@test-graphql-cli/common@beardeddudes/graphql-config@bearbytes/graphql-to-typescript@boltline/apollo-codegen@bn-digital/graphql-configapim-developer-portal-cityaws-appsync-codegen@aws-amplify/amplify-frontend-android@aws-amplify/amplify-frontend-flutter@aws-amplify/amplify-frontend-ios@aws-amplify/amplify-frontend-javascript@apollographql/graphql-language-service-server@backstage-community/plugin-graphiql@backstage/plugin-api-docs@xsoulspace/cactus-sync-clientcdk-codegen@atoms-studio/gluonarc-apollo-codegen-core@apollographql/graphql-language-server@apollographql/graphql-language-service@asiz33/smartblok-vendure-plugin@arbendium/eslint-config-graphql@20minutes/eslint-plugin-graphql@teip/cli@ugql/cli@veecode-platform/plugin-api-docsamplify-codegen2amplify-codegen3amplify-frontend-javascriptamplify-codegenamplify-frontend-iosamplify-frontend-androidamplify-frontend-flutter@amazeelabs/gatsby-source-silverback@divyenduz/graphql-language-server@divyenduz/graphql-language-service@divyenduz/graphql-language-service-interface@divyenduz/graphql-language-service-parser@divyenduz/graphql-language-service-server@divyenduz/graphql-language-service-types@divyenduz/graphql-language-service-utils@divyenduz/ts-graphql-pluginprisma-cli-corequiomnissewing-kit-of-lemonssewing-kittensewing-web-test@eins78/graphql-cliwebpack-config-githubwebql-codegen-clitmp-graphql-config-extension-openapits-gql-pluginugql-clieslint-plugin-graphqleslint-plugin-graphql-linteslint-plugin-graphql-next@emrys-myrddin/eslint-plugin@fedotxxl/graphql-cli-generate-fragments@fevo-tech/graphql-codegen-cli@infinitebrahmanuniverse/nolb-graphql-cfgs
5.0.3

7 months ago

5.0.2

11 months ago

5.0.1

11 months ago

5.0.0

11 months ago

4.5.0

1 year ago

4.4.1

1 year ago

4.4.0

1 year ago

4.3.6

2 years ago

4.3.4

2 years ago

4.3.5

2 years ago

4.3.2

2 years ago

4.3.1

2 years ago

4.3.3

2 years ago

4.3.0

2 years ago

4.2.0

2 years ago

4.1.0

2 years ago

4.0.2

3 years ago

4.0.1

3 years ago

4.0.0

3 years ago

3.4.1

3 years ago

3.4.0

3 years ago

3.3.0

3 years ago

3.2.0

3 years ago

3.1.0

3 years ago

3.0.3

4 years ago

3.0.2

4 years ago

3.0.1

4 years ago

3.0.0

4 years ago

3.0.0-rc.3

4 years ago

3.0.0-rc.2

4 years ago

3.0.0-rc.1

4 years ago

3.0.0-rc.0

4 years ago

2.2.2

4 years ago

3.0.0-alpha.23

4 years ago

3.0.0-alpha.21

4 years ago

3.0.0-alpha.20

4 years ago

3.0.0-alpha.22

4 years ago

3.0.0-alpha.19

4 years ago

3.0.0-alpha.18

4 years ago

3.0.0-alpha.17

4 years ago

3.0.0-alpha.16

4 years ago

3.0.0-alpha.15

4 years ago

3.0.0-alpha.14

5 years ago

3.0.0-alpha.13

5 years ago

3.0.0-alpha.12

5 years ago

3.0.0-alpha.11

5 years ago

3.0.0-alpha.10

5 years ago

3.0.0-alpha.9

5 years ago

3.0.0-alpha.8

5 years ago

3.0.0-alpha.7

5 years ago

3.0.0-alpha.6

5 years ago

3.0.0-alpha.5

5 years ago

3.0.0-alpha.4

5 years ago

3.0.0-alpha.3

5 years ago

3.0.0-alpha.2

5 years ago

3.0.0-alpha.1

5 years ago

3.0.0-alpha.0

5 years ago

2.2.1

6 years ago

2.2.0

6 years ago

2.1.1

6 years ago

2.1.0

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.2.2

6 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.7

6 years ago

1.1.6

6 years ago

1.1.5

6 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago

1.0.0-rc.11

7 years ago

1.0.0-rc.10

7 years ago

1.0.0-rc.9

7 years ago

1.0.0-rc.8

7 years ago

1.0.0-rc.7

7 years ago

1.0.0-rc.6

7 years ago

1.0.0-rc.5

7 years ago

1.0.0-rc.4

7 years ago

1.0.0-rc.3

7 years ago

1.0.0-rc.2

7 years ago

1.0.0-rc.1

7 years ago

1.0.0-rc.0

7 years ago