Apollo Language Server

1.26.9 · deprecated · verified Sun Apr 19

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

Warnings

Install

Imports

Quickstart

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

view raw JSON →