Typescript Context for Apollo Server
See original GitHub issueHey, I’m trying to make the switch over to using Passport to verify email/password logins using GraphQLLocalStrategy
but I’m running into an issue with defining the type of my context. Previously my context looked like:
export interface Context {
req: Request;
res: Response;
prisma: PrismaClient;
smtpTransport: any;
};
And I’m now trying to update the context like:
export interface MyContext extends PassportContext<Context, ExpressRequest>{}
And build my context as follows:
const server = new ApolloServer({
schema,
playground: {
settings: {
"request.credentials": "same-origin",
},
},
context: ({ req, res }): MyContext =>
buildContext({
req,
res,
prisma,
smtpTransport,
}),
});
But I keep running into Property 'logOut' is missing in type 'Context<Request<ParamsDictionary>>' but required in type 'MyContext'
.
How can I update the context type correctly? Thank you!
Issue Analytics
- State:
- Created 3 years ago
- Comments:7
Top Results From Across the Web
Context and contextValue - Apollo GraphQL Docs
During a GraphQL operation, you can share data throughout your server's resolvers and plugins by creating an object named contextValue .
Read more >How can I correctly type the context object in Apollo Server?
I'm using apollo server with typescript and I'm having trouble getting the context parameter inside of my resolver to pick up that the...
Read more >Typescript Context for Apollo Server · Issue #34 - GitHub
Hey, I'm trying to make the switch over to using Passport to verify email/password logins using GraphQLLocalStrategy but I'm running into an ...
Read more >Build a scalable GraphQL server using TypeScript and Apollo ...
Build a scalable GraphQL server using TypeScript and Apollo Server · ## Create a folder mkdir apollo-server · ## Install required modules ·...
Read more >Type safe GraphQL server context with GraphQL Code ...
Add type safety to your GraphQL server context with GraphQL Code Generator plugin " TypeScript ... Apollo CLI TypeScript /GraphQL Codegen.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Sorry for the delayed response. The project where I had been using this package was put on hold and I got some new test-errors after updating the packages. First, if anyone stumbles upon issues with your Request not being valid, make sure that you have the correct definitions (see this issue) by deleting your lock-files and re-installing everything.
I’m not sure that I actually understand the original code example. The definition for the
PassportContext
requires 4 arguments:In the example provided there are only two arguments provided,
Context
andExpressRequest
. My definitions look something like this:As of TS 2.2 there you can add the prisma and smtpTransport just as I did with
dataSources
even though the original context is a type and not an interface. If you want it stricter then perhaps an intersection is a better choice.Sure, I’ll try to have a look at this.