import { Bunjil } from 'bunjil';
constructor
const bunjil: Bunjil = new Bunjil(options);
Create a new instance by passing an options object detailed below.
options
| Property | Type | Description |
|---|---|---|
| debug | boolean | true in your dev environment, but never in production |
| server | ||
| server.port | number | The port to bind on. (Technically optional to support unit/integration tests, but you need it in normal use). |
| server.tracing (optional) Default: false |
boolean undefined | true if you want to enable tracing on the underlying apollo-server |
| server.cacheControl (optional) Default: false |
boolean undefined | true if you want to enable tracing on the underlying apollo-server. |
| server.disableIntrospection | boolean | Disable intropsection queries. This is useful in production to hide your public graphql schema. |
| server.disableBunjilCache | boolean | Set to true to disable Bunjil’s cache, useful when cacheControl is true, as it lets you use Apollo Engine’s caching. |
| _server.useApolloCache | boolean | Enable to print information regarding the cacheability for use with Apollo Engine. |
| _server.useApolloTracing | boolean | Enable to print tracing data for use with Apollo Engine. |
| endpoints | Preceding slash required. | |
| endpoints.graphQL | string | Typically /graphql, this is the location where the GraphQL api is served from. |
| endpoints.graphQL | subscriptions | Typically /graphql, this is the location where the GraphQL subscriptions api is served from. |
| endpoints.graphQL | playground | Typically /graphql, this is the location where the GraphQL playground is served from. |
| policies | Array of Policy | An array of Policy documents. See Policy Reference |
| hooks | ||
| hooks.authentication | function | A Koa middleware function that populates ctx.user with the authenticated user. See Authentication |
| hooks.authorization | function | A hook to allow custom authorization logic. This overrides the policy engine and is not reccomended unless you require a different authorization method. See Authorization |
| playgroundOptions | See Playground |
addSchema({ schemas: [ schema ] })
| Property | Type | Description |
|---|---|---|
| schemas | Array | An array of GraphQL schemas. |
addPrismaSchema({ typeDefs, prisma, contextKey })
Bunjil was designed to wrap generated Prisma bindings, and automatically add a forwardTo around the resolver. This means you can use your Prisma backend, with Bunjil’s authorization infront of it.
| Property | Type | Description |
|---|---|---|
| typeDefs | GraphQL typeDefs | The typeDefs generated by the prisma bindings. |
| prisma | Prisma | The prisma object generated by the prisma bindings. |
| contextKey | string | The key to use when adding this to the GraphQl resolver context, typically database or _db_. |
start()
After you have added your schemas, start your server by awaiting as follows:
await bunjil.start();
The promise will resolve once the server has started.
addContext(key: string, value: any)
With this, you can add anything else to your GraphQL resolver’s context at runtime.
Playground
| Property | Type | Description |
|---|---|---|
| playgroundOptions | ||
| ~.enabled | boolean | |
| ~.endpoint | string | |
| ~.subscriptionsEndpoint | string |