added tenant + graph support

This commit is contained in:
Wyatt Johnson
2018-06-16 17:21:04 -06:00
parent 02e1236792
commit 4318e1ddbe
35 changed files with 1024 additions and 269 deletions
@@ -1,3 +0,0 @@
import playground from 'graphql-playground-middleware-express';
export default () => playground({ endpoint: '/api/graphql' });
-15
View File
@@ -1,15 +0,0 @@
import { graphqlExpress } from 'apollo-server-express';
import { GraphQLSchema } from 'graphql';
import Context from 'talk-server/graph/context';
import { Db } from 'mongodb';
export interface GraphQLOptions {
schema: GraphQLSchema;
db: Db;
}
export default (opts: GraphQLOptions) =>
graphqlExpress(req => ({
schema: opts.schema,
context: new Context({ db: opts.db, req }),
}));
@@ -0,0 +1,16 @@
import { Request, RequestHandler } from 'express';
import { MiddlewareOptions } from 'graphql-playground-html';
import playground from 'graphql-playground-middleware-express';
export type PlaygroundFn = (req: Request) => MiddlewareOptions;
export default (fn: PlaygroundFn): RequestHandler => (req, res, next) => {
// Generate the options.
const options: MiddlewareOptions = fn(req);
// Create the playground handler.
const handler = playground(options);
// Execute it.
handler(req, res, next);
};