@whook/graphiql
v16.1.0
Published
A wrapper for the Whook HTTP Router to provide GraphIQL for local dev
Downloads
27
Maintainers
Readme
@whook/graphiql
A wrapper for the Whook HTTP Router to provide GraphIQL for local dev
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, $);
}