Docs
I'm a Library Author
Loading Config

Loading Config

Load Config

This function is the starting point for using GraphQL Config. It looks for a config file in predefined search places in the current working directory.

A Basic Usage Example (async):

import { loadConfig } from 'graphql-config'
 
async function main() {
  const config = await loadConfig({ ... }) // an instance of GraphQLConfig
}

Synchronous Version:

import { loadConfigSync } from 'graphql-config'
 
function main() {
  const config = loadConfigSync({
    /* ... */
  }) // an instance of GraphQLConfig
}

Options

filepath

type: string

An exact path of a config file.

rootDir

type: string

A path of a directory where GraphQL Config should look for a file (uses process.cwd() by default).

configName

type: string

The name of the config file. It’s graphql by default. Using relay as a config name instructs GraphQL Config to look for all the variations of possible config file names where one of them is relay.config.js.

extensions

type: GraphQLExtensionDeclaration[]

An array of GraphQLExtensionDeclaration objects, is placed to register extensions.

throwOnMissing

type: boolean

GraphQL Config throws an error where there’s no config file by default.

throwOnEmpty

type: boolean

GraphQL Config by default throws an error if there’s a config file but the file is empty.