Coder Social home page Coder Social logo

Comments (6)

vamshiaruru-virgodesigns avatar vamshiaruru-virgodesigns commented on June 20, 2024

Hi @patrick91 , are there any plans to implement this? If there are no plans for implementation, do you know of any strategies for this?
I imagine we have to set the cache-control headers before sending response back. Apollo-server does this by reading the @CacheControl directive. Is there a way for us to do the same using strawberry plugins? Maybe on the on_request_end hook? Can we read directives from this hook in execution_context?
I might not be able to get a clean way of doing this, but if I can get it done even in a rough way I'll be happy to share it :)

from strawberry.

patrick91 avatar patrick91 commented on June 20, 2024

@vamshiaruru-virgodesigns adding cache control directives is easy, doing the caching in an extension is more difficult at the moment.

We do have an example of validation cache here: https://strawberry.rocks/docs/extensions/validation-cache#validationcache this is not what you want, but it could be a start for an implementation :)

from strawberry.

estyxx avatar estyxx commented on June 20, 2024

Hey I started digging into this...
As a first step maybe we can provide the CacheControl directive?

I was thinking about an apollo namespace... but maybe there are better places :)
https://github.com/strawberry-graphql/strawberry/compare/add-cache-control-directive?expand=1

from strawberry.

patrick91 avatar patrick91 commented on June 20, 2024

I think apollo as a namespace might be fine, but I'm not sure if adding the directive is enough, as it can only be used when using federation (or any gateway that knows about this directive)

FYI I'm doing some changes related to schema directives in #2047 (I think the only change that I've not pushed out is b961b3d) so your change should be ok

from strawberry.

vamshiaruru-virgodesigns avatar vamshiaruru-virgodesigns commented on June 20, 2024

Just adding a directive isn't enough I think. I think we have to add proper cache control headers in the request. I might be wrong, but apollo server reads these directives and sets appropriate headers based on the directives, and federation reads values from the header instead of the directive.

from strawberry.

patrick91 avatar patrick91 commented on June 20, 2024

Just adding a directive isn't enough I think. I think we have to add proper cache control headers in the request. I might be wrong, but apollo server reads these directives and sets appropriate headers based on the directives, and federation reads values from the header instead of the directive.

you're right, I didn't read the whole docs:

When using Apollo Federation, the @CacheControl directive and CacheControlScope enum may be defined in a subgraph's schema. An Apollo Server-based subgraph will calculate and set the cache hint for the response that it sends to the gateway as it would for a non-federated Apollo Server sending a response to a client. The gateway will then calculate the cache hint for the overall response based on the most restrictive settings among all of the responses received from the subgraphs involved in query plan execution.

https://www.apollographql.com/docs/apollo-server/performance/caching/#using-with-federation

from strawberry.

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.