mirror of
https://github.com/wassname/talk.git
synced 2026-07-17 11:33:39 +08:00
added tenant + graph support
This commit is contained in:
@@ -1,3 +0,0 @@
|
||||
import playground from 'graphql-playground-middleware-express';
|
||||
|
||||
export default () => playground({ endpoint: '/api/graphql' });
|
||||
@@ -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);
|
||||
};
|
||||
Reference in New Issue
Block a user