npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gqlx-apollo-express-server

v0.6.0

Published

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

Downloads

9

Readme

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({
  port,
  host: 'http://www.example.com',
  services: createServices([
    {
      name: 'default',
      source: `
        type Query {
          hello(name: String): String {
            name ? 'Hello ' + name : 'Hello World'
          }
        }
      `,
      data: {},
    },
  ]),
});

gqlxServer.applyMiddleware(app);
app.listen(port);

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.

Documentation

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.

Contributing

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.

FAQ

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.

Changelog

This project adheres to semantic versioning.

You can find the changelog in the CHANGELOG.md file.

License

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