A wrapper for the Whook HTTP Router to provide GraphIQL for local dev
This module provides the GraphIQL UI to your local Whook server !
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).
Install the module:
npm i @whook/graphiql
Update the types (usually in src/whook.d.ts
):
+import {
+ type WhookGraphIQLEnv,
+ type 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 runProcess
function (usually in
src/index.ts
):
+ import { initHTTPRouter } from '@whook/whook';
+ import wrapHTTPRouterWithGraphIQL from '@whook/graphiql';
// (...)
// It is important to do this in the runProcess function since it really
// make sense only when actually running the server
export async function runProcess(injectedNames = [], $ = new Knifecycle()) {
// (...)
+ // Add support for GraphIQL UI by wrapping and
+ // overriding the original HTTP Router
+ $.register(
+ wrapHTTPRouterWithGraphIQL(initHTTPRouter),
+ );
return await runBaseProcess(injectedNames, $);
}