Last active
September 3, 2020 10:46
-
-
Save DScheglov/927a647667eafe0d569c53f2a864c665 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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