Security News
JavaScript Leaders Demand Oracle Release the JavaScript Trademark
In an open letter, JavaScript community leaders urge Oracle to give up the JavaScript trademark, arguing that it has been effectively abandoned through nonuse.
graphql-config
Advanced tools
The easiest way to configure your development environment with your GraphQL schema (supported by most tools, editors & IDEs)
The graphql-config npm package provides a set of utilities to make it easier to configure and use GraphQL in your development environment. It allows for the centralization of GraphQL project configurations, making it simpler to share settings across different tools such as IDEs, GraphQL clients, and other utilities that work with GraphQL.
Loading GraphQL Project Configuration
This feature allows you to load the GraphQL project configuration. The `loadConfig` function asynchronously loads the configuration from the default or specified configuration file.
const { loadConfig } = require('graphql-config');
async function main() {
const config = await loadConfig();
console.log(config);
}
main();
Getting Schema Information
This feature enables you to retrieve the GraphQL schema information from the configuration. It's useful for tools and applications that need to introspect the schema.
const { loadConfig } = require('graphql-config');
async function main() {
const config = await loadConfig();
const schema = await config.getDefault().getSchema();
console.log(schema);
}
main();
Working with Endpoints
This feature allows for the management of GraphQL API endpoints within the configuration. It simplifies the process of switching between different environments or API versions.
const { loadConfig } = require('graphql-config');
async function main() {
const config = await loadConfig();
const endpoint = config.getDefault().endpoint('default');
console.log(endpoint);
}
main();
graphql-tools is a package that provides a set of utilities for building and working with GraphQL schemas. It is similar to graphql-config in that it helps with GraphQL development, but it focuses more on schema creation, mocking, and stitching, rather than configuration management.
apollo-server is a community-driven, open-source GraphQL server. It's similar to graphql-config in the sense that it's used in GraphQL development environments. However, apollo-server focuses on building and running GraphQL servers, including features like schema definition, data fetching, and request handling, rather than on project configuration.
The easiest way to configure your development environment with your GraphQL schema (supported by most tools, editors & IDEs)
Relay.QL
queries (pending)json
and txt
formats (pending)Did we forget a tool/editor? Please add it here.
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
Note: This requires Node 5 installed or higher
The simplest config specifies only schemaPath
which is path to the file with introspection
results or corresponding SDL document
{
"schemaPath": "schema.graphql"
}
You can specify which files to include/exclude using the corresponding options:
{
"schemaPath": "schema.graphql",
"include": ["*.graphql"],
"exclude": ["temp/**"]
}
You may specify your endpoints info in .graphqlconfig
. The simplest case:
{
"schemaPath": "schema.graphql",
"extensions": {
"endpoint": "https://example.com/graphql"
}
}
In case you need provide addition information for example headers to authenticate your GraphQL endpoint or a endpoint for subscription you can use expanded version:
{
"schemaPath": "schema.graphql",
"extensions": {
"endpoint": {
"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": {
"endpoint": {
"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"
}
}
}
}
}
TBD
Refer to specification use-cases for details
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 NOTE: if you work with files (e.g. editor plugin, linter, etc) use GraphQLConfig class and
getConfigForFile
method to get instance of the correctGraphQLProjectConfig
getGraphQLProjectConfig
should be used by tools that do not work on per-file basis
import { getGraphQLProjectConfig } from 'graphql-config'
const config = getGraphQLProjectConfig()
config.resolveSchema()
.then(schema => {
// use schema for your tool/plugin
})
.catch((err) => {
console.error(err)
})
getGraphQLConfig
should be used by tools that work on per-file basis (editor plugins,
linters, etc.)
import { getGraphQLConfig } from 'graphql-config'
const config = getGraphQLConfig()
config.getConfigForFile(filename)
.resolveSchema()
.then(schema => {
// use schema for your tool/plugin
})
.catch((err) => {
console.error(err)
})
Join our Slack community if you run into issues or have questions. We love talking to you!
FAQs
The easiest way to configure your development environment with your GraphQL schema (supported by most tools, editors & IDEs)
The npm package graphql-config receives a total of 2,880,970 weekly downloads. As such, graphql-config popularity was classified as popular.
We found that graphql-config demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
In an open letter, JavaScript community leaders urge Oracle to give up the JavaScript trademark, arguing that it has been effectively abandoned through nonuse.
Security News
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.