mirror of
https://github.com/wassname/talk.git
synced 2026-08-13 12:40:11 +08:00
22 lines
627 B
TypeScript
22 lines
627 B
TypeScript
import { Request } from "express";
|
|
import { GraphQLSchema } from "graphql";
|
|
import { Db } from "mongodb";
|
|
|
|
import { Config } from "talk-server/config";
|
|
import { graphqlMiddleware } from "talk-server/graph/common/middleware";
|
|
|
|
import TenantContext from "./context";
|
|
|
|
export default async (schema: GraphQLSchema, config: Config, db: Db) => {
|
|
return graphqlMiddleware(config, async (req: Request) => {
|
|
// Load the tenant and user from the request.
|
|
const { tenant, user } = req;
|
|
|
|
// Return the graph options.
|
|
return {
|
|
schema,
|
|
context: new TenantContext({ db, tenant: tenant!, user }),
|
|
};
|
|
});
|
|
};
|