Registry / web-framework / graphql-language-service-server

graphql-language-service-server

JSON →
library2.14.8jsnpmunverified

The GraphQL Language Service Server, currently at version 2.14.8, serves as the backend process for providing rich GraphQL language features within Integrated Development Environments (IDEs). It implements a significant portion of Microsoft's Language Server Protocol (LSP), offering core functionalities such as real-time GraphQL syntax diagnostics, intelligent autocomplete suggestions, and precise hyperlink navigation to fragment definitions and named type declarations. It also provides outline view support for GraphQL queries and facilitates the detection and parsing of GraphQL within template literal tags (e.g., `gql`, `graphql`) across various file types including JavaScript, TypeScript, JSX, TSX, Vue, and Svelte. The package is part of the broader GraphiQL ecosystem, which maintains a consistent release cadence for its components. A key differentiator is its reliance on the `graphql-config` standard for project configuration, enabling robust schema management and multi-project support, although full multi-root workspace support is an ongoing development. This server is the official, specification-compliant backend for GraphQL language tooling.

npm install graphql-language-service-server
INSTALL
IMPORT
SIG · GRAPHQL-LANGUAGE-S
G
graphql-language-service-server
web-frameworkjavascriptv2.14.8
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

startServer
import { startServer } from 'graphql-language-service-server';
const { startServer } = require('graphql-language-service-server');
The library primarily uses ES modules. Use `import` syntax. Requires Node.js ES module support or a transpilation step.
startServer
await startServer({ method: 'node' });
The `startServer` function is asynchronous and returns a Promise. Always `await` its call.

This quickstart demonstrates how to programmatically start the GraphQL Language Service Server. It initializes the server using Node.js IPC for communication and highlights the essential `graphql-config` setup required for operation.

import { startServer } from 'graphql-language-service-server'; import { loadConfig } from 'graphql-config'; // Ensure 'graphql-config' is installed async function initializeLanguageServer() { // A graphql.config.js, .graphqlrc.yml, etc. is required in your project root. // Example graphql.config.js: // module.exports = { // schema: './schema.graphql', // documents: './src/**/*.graphql', // extensions: { // endpoints: { // default: { // url: 'http://localhost:4000/graphql', // headers: { // Authorization: `Bearer ${process.env.GRAPHQL_TOKEN || ''}`, // }, // }, // }, // }, // }; const config = await loadConfig(); if (!config) { console.error('Error: A graphql-config file (.graphqlrc.yml, graphql.config.js, etc.) is required in your project.'); process.exit(1); } console.log('Starting GraphQL Language Service Server via IPC (Node.js method)...'); // 'method: "node"' uses Node.js IPC (stdin/stdout) for communication with the LSP client. // Other methods include 'socket' and 'streams'. await startServer({ method: 'node', // You can pass the loaded config directly if needed, but the server // typically discovers it automatically based on the 'configDir'. // config, // configDir: process.cwd(), }); console.log('GraphQL Language Service Server successfully started. Waiting for LSP client messages.'); } initializeLanguageServer().catch(error => { console.error('Failed to initialize GraphQL Language Service Server:', error); process.exit(1); });
graphql-language-service-server --version
Debug
Known issues
gotchaA `graphql-config` file (e.g., `.graphqlrc.yml`, `graphql.config.js`) is mandatory for the language server to function correctly. Without it, the server cannot determine your schema, documents, or project settings.
fix
Create a `graphql-config` file in your project root or specify its path via server options.
affects: >=2.0.0
breakingThe server requires Node.js version `^18.18.0` or `>=20.9.0` for full compatibility and optimal performance. Older Node.js versions may encounter errors or unexpected behavior.
fix
Ensure your Node.js environment meets the specified version requirements. Update Node.js if necessary.
affects: >=2.0.0
gotchaChanges to your `graphql-config` file or other relevant project settings may not immediately be picked up by a running language server. You might need to restart your IDE or the language server process manually for changes to take effect.
fix
After modifying configuration files, restart your editor or the LSP server process.
affects: >=2.0.0
gotchaWhile `graphql-config` supports multi-project setups, the GraphQL Language Service Server does not yet fully support multi-root workspaces within IDEs like VS Code. This can lead to unexpected behavior when dealing with multiple distinct project roots in a single editor instance.
fix
Organize your projects to use a single `graphql-config` file for the entire workspace or open distinct project folders separately until multi-root support is implemented.
affects: >=2.0.0
Errors
Common errors & fixes
Cannot use import statement outside of a module
Attempting to use ES module `import` syntax in a CommonJS (`.js` without `"type": "module"` in `package.json`, or a `.cjs` file) context.
fix
Ensure your Node.js project is configured for ES modules (`"type": "module"` in `package.json`) or use a transpiler like Babel/TypeScript to convert `import` to `require` for CommonJS environments.
Error: A graphql-config file (.graphqlrc.yml, graphql.config.js, etc.) is required in your project.
The language server failed to find or load a `graphql-config` file in the expected locations.
fix
Create a valid `graphql-config` file (e.g., `.graphqlrc.yml`, `graphql.config.js`) in your project's root directory or the directory where the server is expected to operate.
[ERROR] .../vim/lsp/rpc.lua:430 "rpc" "graphql-lsp" "stderr" '... graphql-language-service'
A generic error indicating a failure in the Language Server Protocol (LSP) communication or an issue within the `graphql-language-service-server` process itself, often seen in LSP client logs.
fix
Check the server's standard error output for more specific messages. Verify Node.js version, `graphql-config` validity, and ensure all peer dependencies are installed. Debug the server process if running manually.
Upgrade
Version history
2.14.8latest on npm
Audit
Dependencies
graphqlrequiredPeer dependency for GraphQL schema and language parsing.
graphql-configrequiredRequired for configuring GraphQL projects, schemas, and documents for the language server. Not a direct `package.json` dependency but critical for operation.
Agent activity
10 hits · last 30 days
node
10
Resources
graphql-language-service-server — npm install graphql-language-service-server · libregistry