Giter Club home page Giter Club logo

Comments (7)

ElectronicBeef avatar ElectronicBeef commented on August 25, 2024 1

Closing this since it is fixed now.

from connect-redis.

wavded avatar wavded commented on August 25, 2024

I am not familiar with Apollo and what it may do the the request objects but a cursory view of your code would suggest me that somehow the express middleware and the Apollo resolvers are not sharing the same request object. If you provide a minimal example that runs and demonstrates the issue, I can take a further look.

from connect-redis.

ElectronicBeef avatar ElectronicBeef commented on August 25, 2024

I am not familiar with Apollo and what it may do the the request objects but a cursory view of your code would suggest me that somehow the express middleware and the Apollo resolvers are not sharing the same request object. If you provide a minimal example that runs and demonstrates the issue, I can take a further look.

Thank you for the quick response! :) I've uploaded a running repo: https://github.com/ElectronicBeef/Reddit-Clone

from connect-redis.

wavded avatar wavded commented on August 25, 2024

@ElectronicBeef Unfortunately, this isn't really runnable for me. It requires a postgres database to start the project. Is there any more minimal version that only has an external Redis dependency that demonstrates the issue?

from connect-redis.

ElectronicBeef avatar ElectronicBeef commented on August 25, 2024

@ElectronicBeef Unfortunately, this isn't really runnable for me. It requires a postgres database to start the project. Is there any more minimal version that only has an external Redis dependency that demonstrates the issue?

Sorry, my bad! I've created a new minimalistic repo that doesn't require a postgres database: https://github.com/ElectronicBeef/connect-redis-session-issue

from connect-redis.

wavded avatar wavded commented on August 25, 2024

I can run this, thx. In your example, the req object is undefined in your resolver so session is also undefined as a result. Seems like those context values aren't even making it to the resolver:

@Resolver()
export class Hello {
  @Query(() => String)
  hello(@Ctx("req") { req }: MyContext) {
    console.log(req) // <-- this is undefined
    // ...
}

from connect-redis.

ElectronicBeef avatar ElectronicBeef commented on August 25, 2024

I can run this, thx. In your example, the req object is undefined in your resolver so session is also undefined as a result. Seems like those context values aren't even making it to the resolver:

@Resolver()
export class Hello {
  @Query(() => String)
  hello(@Ctx("req") { req }: MyContext) {
    console.log(req) // <-- this is undefined
    // ...
}

Thanks for the hunch in the right direction, I finally fixed it and the error may be slightly embarrassing. I just had to change the code for my context from this:
expressMiddleware(apolloServer, { context: async ({ req }) => ({ req }), })
To this:
expressMiddleware(apolloServer, { context: async ({ req }) => ({ req: req.session }), })

from connect-redis.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.