# @koikorn/app-schema-router

> KeystoneJS GraphQL App.

Latest version **5.1.1** (published 2020-07-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install @koikorn/app-schema-router
pnpm add @koikorn/app-schema-router
yarn add @koikorn/app-schema-router
bun add @koikorn/app-schema-router
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: no vulnerabilities; high maintenance score.

Warnings: low downloads; no types; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 5.1.1 |
| Published | 2020-07-13 |
| First published | 2020-07-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=10.0.0 |
| Dependencies | 0 |
| Unpacked size | 4.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 9983 |
| Author | The KeystoneJS Development Team |
| Maintainers | lorenhaim |

## Links

- npm: https://www.npmjs.com/package/@koikorn/app-schema-router
- Repository: https://github.com/keystonejs/keystone/tree/master/packages/app-schema-router
- npm.io page: https://npm.io/package/@koikorn/app-schema-router

## Recent versions

- 5.1.1 (latest) — 2020-07-13

## README

<!--[meta]
section: api
subSection: apps
title: GraphQL Schema Router
[meta]-->

# GraphQL Schema Router

[![View changelog](https://img.shields.io/badge/changelogs.xyz-Explore%20Changelog-brightgreen)](https://changelogs.xyz/@koikorn/app-schema-router)

A KeystoneJS App that route requests to different GraphQL schemas.

The `SchemaRouterApp` allows you to define a `routerFn` which takes `(req, res)` and returns
a `routerId`, which is used to pick between different GraphQL schemas which exist at the same
`apiPath`.

## Usage

```javascript
const { Keystone } = require('@koikorn/keystone');
const { GraphQLAppPlayground } = require('@koikorn/app-graphql-playground');
const { SchemaRouterApp } = require('@koikorn/app-schema-router');
const { GraphQLApp } = require('@koikorn/app-graphql');
const { AdminUIApp } = require('@koikorn/app-admin-ui');

module.exports = {
  keystone: new Keystone(),
  apps: [
    new GraphQLAppPlayground({ apiPath })
    new SchemaRouterApp({
      apiPath,
      routerFn: (req) => req.session.keystoneItemId ? 'private' : 'public',
      apps: {
        public: new GraphQLApp({ apiPath, schemaName: 'public', graphiqlPath: undefined }),
        private: new GraphQLApp({ apiPath, schemaName: 'private', graphiqlPath: undefined }),
      },
    }),
    new AdminUIApp()
  ],
};
```

## Config

| Option     | Type       | Default      | Description                                                    |
| ---------- | ---------- | ------------ | -------------------------------------------------------------- |
| `apiPath`  | `String`   | `/admin/api` | The GraphQL API path                                           |
| `routerFn` | `Function` | `() => {}`   | A function which takes `(req, res)` and returns a `routerId`   |
| `apps`     | `Object`   | `{}`         | An object with `routerId`s as keys and `GraphQLApp`s as values |

---
_Source: https://npm.io/package/@koikorn/app-schema-router · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
