import { IncomingMessage } from 'http' ; import { Context as ApolloContext } from 'apollo-server-core' ; import { PrismaClient , User } from '@prisma/client' ; import { prisma } from '../lib/prisma' ; import { verifyAuthHeader } from '../services/auth' ; param context export async function createContext ( context ) { const authHeader = verifyAuthHeader ( context . req . headers . authorization ) ; let user = null ; if ( authHeader ) { user = await prisma . user . findUnique ( { where : { id : authHeader . userId } } ) ; } return { db : prisma , prisma , user , } ; } type ApolloApiContext = ApolloContext < { req : IncomingMessage ; } > ; export type Context = { db : PrismaClient ; prisma : PrismaClient ; user : User | null ; } ;