Comments (6)
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.
@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.
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.
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.
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.
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)
- "Getting Started" instructions resulting in a "Not Found" when accessing GraphiQL HOT 4
- Allow access to StrawberryField.metadata in a query level. HOT 15
- Implement scalars using Annotated HOT 1
- Breaking in 0.217.0: kwargs in has_permission changed to snake_case HOT 3
- CI: send coverage reports to Codecov once when all tests are done
- Fields defined with `... = field(resolver=...)` are treated like regular dataclass attributes by type checkers
- has_permission function is raising a runtime warning: coroutine 'SyncToAsync.__call__' was never awaited. HOT 1
- Do the Lazy-Types support Union?
- Pyright type issue with strawberry.file_uploads.Upload HOT 1
- a custom resolver with permission_classes doesn't accept @sync_to_async decorator
- ASGI WebSocket connections’ scope issue: KeyError: 'subprotocols' HOT 2
- Cannot return null for non-nullable field Subscription.count HOT 5
- Unable to annotate union names with generics HOT 7
- Can Strawberry created dataclasses be `frozen` by default? HOT 3
- AttributeError when query passed is a list and not a dict HOT 6
- Errors when closing a subscription after authentication failure HOT 1
- Add support for `@stream` and `@defer`
- Document all the scalars we have
- Allow Boolean operators for Permissions
- `ApolloTracingExtension` raises deprecation warning.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from strawberry.