Files
talk/src/core/server/graph/tenant/middleware.ts
T

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 }),
};
});
};