strawberry-graphql / strawberry

A GraphQL library for Python that leverages type annotations 🍓
https://strawberry.rocks
MIT License
3.93k stars 516 forks source link

DataLoader custom cache cannot be used with redis #3290

Open davidnemec opened 9 months ago

davidnemec commented 9 months ago

Describe the Bug

DataLoader custom cache cannot be used with redis even thought docs mentions it's possible.

Additional Context

The issue seems to be that dataloader calls get/set methods of custom cache class but expects/works only with Future type.

I can help fixing this but I'm not sure what would be the proper way to handle this.

Upvote & Fund

Fund with Polar

patrick91 commented 9 months ago

hi @davidnemec! I think a small reproduction would be really helpful 😊

davidnemec commented 9 months ago

Did a small repository here.

Dartt0n commented 1 month ago

Any updates on the issue?

erikwrede commented 1 month ago

The issue is that the redis cache does not return futures. To fix this, you'd need to manually wrap the cached results in futures again. Additionally, the cache needs a reference to the current event loop to create these futures.

However, we could improve usability here. There can be valid cases, like yours, where the cache cannot not store any futures, but just the loaded results. This would be a breaking change to the caching interface. Personally, I'd find a DataLoader cache working with AwaitableOrValue a lot more intuitive than the current version.

What were the considerations and choices that led to the current design? /cc @DoctorJohn @patrick91