Apollo Language Server
The Apollo Language Server is a deprecated JavaScript/TypeScript package designed to provide advanced language features for Apollo GraphQL projects within integrated development environments (IDEs). Last actively maintained at version 1.26.9 and published approximately four years ago, it aimed to offer capabilities such as syntax highlighting, real-time validation, autocompletion, and schema navigation for GraphQL files and embedded GraphQL templates. Its core functionality has since been integrated directly into the official Apollo GraphQL VS Code extension and other Apollo tooling, rendering this standalone package largely obsolete for modern development. As such, it is no longer actively developed or recommended for new projects, with its primary function superseded by a more integrated editor experience. Developers should utilize the VS Code extension for current Apollo GraphQL language support.
Common errors
-
Cannot find module 'apollo-language-server/lib/index.js'
cause The language server is typically invoked as a child process by an editor extension, not directly imported. This error may occur if an LSP client attempts to load the module incorrectly or if the package is not correctly installed.fixEnsure `apollo-language-server` is installed in your project's `node_modules`. If you are trying to use it programmatically as a library, reconsider your approach; it is designed as a standalone process. For editor features, install the Apollo GraphQL VS Code extension. -
Error: GraphQL service is not running. Please restart VS Code.
cause This error typically indicates that the language server process failed to start or crashed, which is often managed by the VS Code extension. It can be due to corrupted caches, misconfigurations, or conflicts.fixRestart VS Code. If the issue persists, try clearing the VS Code cache, ensuring your `apollo.config.js` or `apollo.config.json` file is correctly configured at your project root, and checking the VS Code output panel for 'Apollo GraphQL' for more specific error messages. Ensure your Node.js version meets the `engines` requirement (>=8).
Warnings
- breaking The `apollo-language-server` package is deprecated and no longer actively maintained. Its functionality has been integrated into the 'Apollo GraphQL' VS Code extension and other Apollo tooling. New projects should not rely on this package directly.
- gotcha This package is an implementation of a Language Server and is intended to be run as a separate process (e.g., by an editor extension) communicating via stdin/stdout using the Language Server Protocol. It is not designed to be imported as a library for direct programmatic use within application code.
- gotcha Older versions of the Apollo Language Server, particularly when dealing with large or complex GraphQL projects, have been reported to exhibit slow performance for features like 'Go to Definition' or general IntelliSense suggestions, especially on Windows.
Install
-
npm install apollo-language-server -
yarn add apollo-language-server -
pnpm add apollo-language-server
Imports
- Not applicable for direct application import
// The apollo-language-server package is designed to be run as a standalone process // and communicates via the Language Server Protocol (LSP) over stdin/stdout. // It is not typically imported as a library into other JavaScript/TypeScript applications. // Instead, editor extensions (like the Apollo GraphQL VS Code extension) invoke it as a child process.
Quickstart
/*
This quickstart demonstrates how a Language Server Protocol (LSP) client,
such as an IDE extension, might theoretically invoke the apollo-language-server
as a child process.
Direct programmatic use of this package in a typical application is not intended
or recommended, especially given its deprecated status.
Users seeking Apollo GraphQL language features should install the official
'Apollo GraphQL' VS Code extension or similar editor integrations.
*/
import { spawn } from 'child_process';
import path from 'path';
const languageServerPath = path.resolve(
__dirname,
'node_modules',
'apollo-language-server',
'lib',
'index.js'
);
const languageServerProcess = spawn(
'node',
[languageServerPath],
{ stdio: ['pipe', 'pipe', 'pipe'] }
);
languageServerProcess.stdout.on('data', (data) => {
console.log(`LSP Server stdout: ${data}`);
// In a real LSP client, this data would be parsed as LSP messages
// and used to update editor features (diagnostics, completions, etc.)
});
languageServerProcess.stderr.on('data', (data) => {
console.error(`LSP Server stderr: ${data}`);
});
languageServerProcess.on('close', (code) => {
console.log(`LSP Server process exited with code ${code}`);
});
// Example: Sending an initialize request (simplified, actual LSP has headers)
const initializeRequest = {
jsonrpc: '2.0',
id: 1,
method: 'initialize',
params: {
processId: process.pid,
rootUri: `file://${process.cwd()}`,
capabilities: { /* client capabilities here */ }
}
};
function sendLSPMessage(message: any) {
const content = JSON.stringify(message);
const contentLength = Buffer.byteLength(content, 'utf8');
const header = `Content-Length: ${contentLength}\r\nContent-Type: application/json\r\n\r\n`;
languageServerProcess.stdin.write(header + content);
}
// In a real client, you'd send more messages (didOpen, didChange, etc.)
// For this quickstart, we'll just demonstrate starting and sending one message.
// In a real scenario, there would be a full LSP communication loop.
// To prevent the example from hanging indefinitely in a CI environment
setTimeout(() => {
console.log('Terminating example LSP client after some time.');
languageServerProcess.kill();
}, 5000);