Skip to content

Instantly share code, notes, and snippets.

@DScheglov
Last active September 3, 2020 10:46
Show Gist options
  • Save DScheglov/927a647667eafe0d569c53f2a864c665 to your computer and use it in GitHub Desktop.
Save DScheglov/927a647667eafe0d569c53f2a864c665 to your computer and use it in GitHub Desktop.
import Express from 'express';
import diContainer from 'true-di';
import createDataAccessService from '../services/data-access-service';
import createAuthorizationService from '../services/authorization-service';
import { IApolloContext } from '../interfaces';
const createContext = (dbConnection: Promise<Connection>) => ({ req }: { req: Express.Context }) =>
dbConnection.then(
conn => diContainer<IApolloContext>({
dataAccessService: () => createDataAccessService(conn),
authorizationService: ({ dataAccessService }) => createAuthorizationService(
dataAccessService,
req.headers['X-Authorization']
);
})
);
export default createContext;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment