@whook/graphiql
TypeScript icon, indicating that this package has built-in type declarations

16.1.0 • Public • Published

@whook/graphiql

A wrapper for the Whook HTTP Router to provide GraphIQL for local dev

GitHub license

This module provides the GraphIQL UI to your local Whook server !

Usage

The DEV_MODE=1 environment variable must be used when starting your server (the npm run dev script of default Whook projects does it by default).

Setup

Install the module:

npm i @whook/graphiql

Update the types (usually in src/whook.d.ts):

+import type {
+   WhookGraphIQLEnv,
+   WhookGraphIQLConfig,
+} from '@whook/graphiql';

// ...

declare module 'application-services' {

  export interface AppEnvVars
    extends BaseAppEnvVars,
      WhookBaseEnv,
      // (...)
+      WhookGraphIQLEnv,
      WhookSwaggerUIEnv {}

  // (...)

  export interface AppConfig
    extends WhookBaseConfigs,
      // (...)
+      WhookGraphIQLConfig,
      JWTServiceConfig {}

  // ...

}

Then, just wrap the HTTP router with this module and register it again with the Knifecycle instance inside the runServer function (usually in src/index.ts):

+ import initHTTPRouter from '@whook/http-router';
+ import wrapHTTPRouterWithGraphIQL from '@whook/graphiql';

// (...)

// It is important to do this in the runServer function since it really
//  make sense only when actually running the server
export async function runServer(injectedNames = [], $ = new Knifecycle()) {

  // (...)

+  // Add support for GraphIQL UI by wrapping and
+  //  overriding the original HTTP Router
+  $.register(
+    wrapHTTPRouterWithGraphIQL(initHTTPRouter),
+  );

  return await runBaseServer(injectedNames, $);
}

API

Authors

License

MIT

Package Sidebar

Install

npm i @whook/graphiql

Weekly Downloads

24

Version

16.1.0

License

MIT

Unpacked Size

55 kB

Total Files

11

Last publish

Collaborators

  • nfroidure