0.3.3 • Published 5 years ago

@britishcouncil/grizzly v0.3.3

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

@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:

KeyTypeDefaultNotes
graphqlServicesArray of GrizzlyGraphQLServernullSee GrizzlyGraphQLServer documentation below for more details about this type
sessionStoreStorenullAn instance of a session storage for Express server.
passportAuthenticatornullAn instance of a passport authenticator.
middlewaresArray of ExpressMiddlewarenullEach ExpressMiddleware can have a path (optional) and a function, e.g. { path: "/hello-world", function: () => "Hello world!" } or { function: () => console.log("Everything") }
portstring or numberprocess.env.PORT or 5000HTTP server port.
hosthostSee https://nodejs.org/api/net.html#net_server_listenHTTP server binding address.
sessionSessionOptions{ secret: process.env.SESSION_SECRET, cookie: { maxAge: 3600000 } // 3600000ms = 1h. }Sessions options
corsCorsOptionsnullCors configuration.
bodyParseObject or booleanfalseThe 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:

KeyTypeDefaultNotes
schemaFilestringnullPath 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)
endpointstring"/graphql"The endpoint with which register the GraphQL service to the Express app.
middlewaresarray of GraphQLMiddlewarenull

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:

KeyTypeDefaultNotes
pgConfigPool or PoolConfig or stringnullPostgreSQL connection string or object.
schemaNamestring 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>;
}