silverstripe / silverstripe-graphql

Serves Silverstripe data as GraphQL representations
BSD 3-Clause "New" or "Revised" License
52 stars 61 forks source link

Support granular caching through smart proxies #183

Open chillu opened 6 years ago

chillu commented 6 years ago

Overview

Our GraphQL approach is quite slow, because we create an in-memory representation of the entire schema on each execution, and as usual, caching is hard. While we should generally improve the performance of our module, we also need to allow faster layers outside of SilverStripe to be used effectively.

Due to the nature of GraphQL, this is not (easily) achieved through standard framework features like setting HTTP caching headers and using intermediary caches like CDNs. There's too many permutations of requests.

Acceptance Criteria

Notes

chillu commented 5 years ago

Looking at this again. Since I've wrote the initial post, Apollo Engine introduced Automated Persisted Queries. In short, it means if you proxy your GraphQL endpoint through Apollo Engine, front it with your own CDN, and use Apollo Client with this setting, most of the traffic will terminate at your CDN. And you don't need to configure or support persisted queries in your GraphQL endpoint, that's handled transparently.

Unfortunately it doesn't look like the Apollo Cache Standard is getting a lot of adoption. But fortunately, we need to add cache signals to our API surface regardless, even if it only computes a single cache signal for the entire response (via HTTP headers).

There's other GraphQL caching engines, approaches and services popping up:

chillu commented 5 years ago

Proposed scaffolding syntax:

SilverStripe\GraphQL\Controller:
  schema:
    scaffolding:
      types:
        MyProject\Post:
          fields: 
            ID: true
            IsFeatured: true
            Comments:
              cacheControl:
                maxAge: 10
          cacheControl:
            maxAge: 60
        MyProject\Comment:
          fields: [Comment, Author]
          cacheControl:
            maxAge: 60
maxime-rainville commented 5 years ago

Should we ping OPS about this? Presumably, they'll need to do some updates for CWP/SSP customers to fully benefit from this feature/

chillu commented 3 years ago

Kicking this out of the epic. The Terraformers have proven in their PWA build that persisted queries are possible without too much faff, and those should be cacheable by a CDN. Anything more granular will have to wait.