Apollo Language Server

raw JSON →
1.26.9 verified Sun Apr 19 auth: no javascript deprecated

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.

error 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.
fix
Ensure 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 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.
fix
Restart 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).
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.
fix Migrate to the official 'Apollo GraphQL' VS Code extension (or corresponding IDE integration) for current GraphQL language features and support. If programmatic GraphQL tooling is required, explore `@apollo/server` for server implementations or `@graphql-tools/*` for schema utilities.
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.
fix Do not attempt to `import` and use symbols from `apollo-language-server` in your application. Instead, install the Apollo GraphQL VS Code extension or understand that your IDE uses a bundled or separately installed language server process.
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.
fix Ensure you are using the latest available version (1.26.9), though active maintenance has ceased. For optimal performance and features, use the actively developed Apollo GraphQL VS Code extension which incorporates more recent optimizations and updated tooling.
npm install apollo-language-server
yarn add apollo-language-server
pnpm add apollo-language-server

This quickstart illustrates how a host application or editor extension might start and communicate with the Apollo Language Server as an external process using the Language Server Protocol (LSP). It simulates sending an 'initialize' request, which is the first message an LSP client sends to a server. This package is not designed for direct application imports, as its functionality is consumed by editor extensions.

/*
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);