Skip to content
This repository has been archived by the owner. It is now read-only.
Slightly opinionated GraphQL server solution.
TypeScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.rsrc
examples
src
.gitignore
README.md
package.json
tsconfig.json
yarn.lock

README.md

@britishcouncil/grizzly

Slightly opinionated GraphQL server solution built on Apollo Server, PostGraphile and Express.

Overview

  • All the features of the latest Apollo Server, plus
  • All the features of the latest PostGraphile
  • Create multiple GraphQL services (i.e. Apollo or PostGraphile services) over a single Express application

Install

yarn add @britishcouncil/grizzly # npm install @britishcouncil/grizzly

Usage

Quickstart

To get started with @britishcouncil/grizzly, have a look at the examples.

API

GrizzlyExpress

constructor(props: GrizzlyExpressProps): GrizzlyExpress

The props argument accepts the following fields:

Key Type Default Notes
graphqlServices Array of GrizzlyGraphQLServer null See GrizzlyGraphQLServer documentation below for more details about this type
sessionStore Store null An instance of a session storage for Express server.
passport Authenticator null An instance of a passport authenticator.
middlewares Array of ExpressMiddleware null Each ExpressMiddleware can have a path (optional) and a function, e.g. { path: "/hello-world", function: () => "Hello world!" } or { function: () => console.log("Everything") }
port string or number process.env.PORT or 5000 HTTP server port.
host host See https://nodejs.org/api/net.html#net_server_listen HTTP server binding address.
session SessionOptions { secret: process.env.SESSION_SECRET, cookie: { maxAge: 3600000 } // 3600000ms = 1h. } Sessions options
cors CorsOptions null Cors configuration.
bodyParse Object or boolean false The body-parser options: false removes the body parser middleware and true uses the defaults

GrizzlyApollo

constructor(options: GrizzlyApolloConfig): GrizzlyApollo

The options argument accepts all the parameters as the options argument by Apollo Server 2.0, but it also adds:

Key Type Default Notes
schemaFile string null Path to a GraphQL schema written in SDL. If this parameter is specified, there will be no need to specify either typeDefs or schema (see Apollo Server options)
endpoint string "/graphql" The endpoint with which register the GraphQL service to the Express app.
middlewares array of GraphQLMiddleware null

GrizzlyPostGraphile

constructor(options: GrizzlyPostGraphileOptions): GrizzlyPostGraphile

The options argument accepts all the parameters as the options argument by postgraphile() (see also PostGrpahileOptions interface), but it also merges into it the other two parameters of the postgraphile() function:

Key Type Default Notes
pgConfig Pool or PoolConfig or string null PostgreSQL connection string or object.
schemaName string or Array<string> "public" PostgreSQL schema(s) you to expose via PostGraphile.

Types

/**
 * Session options.
 */
export interface SessionOptions {
  secret?: string;
  cookie?: CookieOptions;
}

/**
 * General interace for GraphQL servers.
 */
export interface GrizzlyGraphQLServer {
  endpoint?: string;
  applyMiddleware({
    app,
    path,
    cors,
    bodyParserConfig,
    disableHealthCheck,
    onHealthCheck
  }: ServerRegistration): void;
}

/**
 * Type for express middlewares. Path is optional.
 */
export interface ExpressMiddleware {
  path?: string;
  function: Function;
}

/**
 * Grizzly Express initialisation options.
 */
export interface GrizzlyExpressProps {
  graphqlServices: Array<GrizzlyGraphQLServer>;
  sessionStore?: Store;
  passport?: Authenticator;
  middlewares?: Array<ExpressMiddleware>;
  port?: string | number;
  address?: string;
  cors?: CorsOptions;
  session?: SessionOptions;
  bodyParser?: Object | boolean;
}

/**
 * Extends ApolloServer Config.
 */
export interface GrizzlyApolloConfig extends ApolloConfig {
  schemaFile?: string;
  endpoint?: string;
  middlewares?: Array<any>;
}

/**
 * Extends PostGraphile Config.
 */
export interface GrizzlyPostGraphileOptions extends PostGraphileOptions {
  pgConfig?: Pool | PoolConfig | string;
  schemaName?: string | Array<string>;
}
You can’t perform that action at this time.