GithubHelp home page GithubHelp logo

jimkyndemeyer / graphql-config Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kamilkisiela/graphql-config

0.0 2.0 0.0 696 KB

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

License: MIT License

TypeScript 100.00%

graphql-config's Introduction

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!

graphql-config's People

Contributors

akre54 avatar alloy avatar asiandrummer avatar felipeptcho avatar greenkeeper[bot] avatar ivangoncharov avatar jaydenseric avatar jnwng avatar julianbauer avatar kbrandwijk avatar lvarayut avatar nicolaslopezj avatar nodkz avatar petetnt avatar renovate-bot avatar renovate[bot] avatar romanhotsiy avatar schickling avatar stephen avatar timsuchanek avatar tonyxiao avatar wtgtybhertgeghgtwtg avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.