TypeScript icon, indicating that this package has built-in type declarations

0.6.0 • Public • Published

gqlx Node.js Express Middleware using Apollo Server

Build CI npm node GitHub tag GitHub issues

An opinionated Express middleware bringing a pre-configured Apollo server with gqlx support to your project.

gqlx Logo

Getting Started

To get started just install the package via npm.

npm i gqlx-apollo-express-server

Since Express is used as a peer dependency you need to have it installed already or you'll need to install it.

import * as express from 'express';
import { configureGqlx, createServices } from 'gqlx-apollo-express-server';

const port = +(process.env.PORT || 3000);
const app = express();
const gqlxServer = configureGqlx({
  host: '',
  services: createServices([
      name: 'default',
      source: `
        type Query {
          hello(name: String): String {
            name ? 'Hello ' + name : 'Hello World'
      data: {},


The gqlx-apollo-express-server is service-based, i.e., we have to supply services for performing the GraphQL resolver duty. The advantage is that we can easily swap services during runtime, e.g., if these services relate to independent functionality such as microservices which are updated during we can reflect these updates in the GraphQL instance as well - without having to restart the server.


A Node.js Express middleware for integrating an Apollo server supporting gqlx.

All you need is to use the configureGqlx method for configuring everything you need. The object is ready to be used on an express application. It will install multiple middlewares (depending on the configuration) to serve GraphQL (and potentially some other stuff, such as an GraphiQL instance).

// ...
import { configureGqlx } from 'gqlx-apollo-express-server';

const app = express();
configureGqlx({ port, /* ... */ }).applyMiddleware(app);

Right now the following options are supported:

interface GatewayOptions<TApi, TData> {
   * The port of the server.
  port: number;
   * The (external) hostname for lookups.
  host: string;
   * The different services to register.
  services: Array<Service<TApi, TData>>;
   * The optional keep alive in milliseconds.
  keepAlive?: number;
   * Activates the optional tracing.
  tracing?: boolean;
   * Activates the optional cache-control.
  cacheControl?: boolean;
   * Optionally, sets the max. size of a file (in bytes).
  maxFileSize?: number;
   * Optionally, sets the max. number of files to upload.
  maxFiles?: number;
   * Defines an error formatter.
   * @param error The error to format.
   * @returns The formatted error message.
  formatter?(error?: string): any;
   * Creates the API to be used by the services.
  createApi?: ApiCreator<TApi, TData>;
   * Optionally, changes the used server paths.
  paths?: ServerPaths;

Only the first three (port, host, and services) are required.


We are totally open for contribution and appreciate any feedback, bug reports, or feature requests. More detailed information on contributing incl. a code of conduct are soon to be presented.


What needs to be configured?

Only a bare minimum of configuration is necessary. The getting started contains a sample using only the required options. What services to expose and how these are defined is fully up to you.


This project adheres to semantic versioning.

You can find the changelog in the file.


gqlx-apollo-express-server is released using the MIT license. For more information see the LICENSE file.

Package Sidebar


npm i gqlx-apollo-express-server

Weekly Downloads






Unpacked Size

53.6 kB

Total Files


Last publish


  • florianrappl