Altair Express Middleware

8.5.2 · active · verified Wed Apr 22

Altair Express Middleware is an active and frequently updated Express.js middleware designed to serve the Altair GraphQL Client UI. Currently at version 8.5.2, it provides a convenient way to self-host the full-featured Altair GraphQL Client within an Express application, allowing developers to interact with GraphQL APIs directly from their server. Recent releases, such as v8.5.0, introduced significant enhancements like Zod validation for initialization options and plugin schemas, and v8.2.8 brought stricter Content Security Policy (CSP) enforcement with nonces, improving security. The package aims for a regular release cadence to align with the main Altair GraphQL Client, offering features like query execution, schema introspection, and subscription support. Its key differentiator is the tight integration with the comprehensive Altair client experience, contrasting with simpler embedded GraphQL explorers.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates setting up a basic Express server with a placeholder GraphQL endpoint and integrating the Altair GraphQL Client UI middleware, accessible at `/altair`.

import express from 'express';
import { altairExpress } from 'altair-express-middleware';

const app = express();
const PORT = process.env.PORT || 3000;

// A placeholder GraphQL endpoint for Altair to connect to
app.all('/graphql', (req, res) => {
  // In a real application, this would be your GraphQL API handler
  res.status(200).send('This is your GraphQL endpoint. Altair will interact with it.');
});

// Integrate Altair GraphQL Client UI
app.use('/altair', altairExpress({
  endpointURL: '/graphql',
  subscriptionsEndpoint: '/graphql',
  // Example of a common option: setting an initial query
  initialQuery: `query {
    __typename
  }`,
  // As of v8.5.0, these options are Zod-validated.
  // Ensure your options strictly adhere to AltairExpressOptions type.
  // Example of a newer option (introduced in v8.4.2) for allowed local storage keys
  // allowedLocalStorageKeys: ['myCustomKey', 'anotherKey']
}));

app.listen(PORT, () => {
  console.log(`🚀 GraphQL API server running on http://localhost:${PORT}/graphql`);
  console.log(`✨ Altair GraphQL Client UI available on http://localhost:${PORT}/altair`);
});

view raw JSON →