Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(compose): respect other @composeDirective definitions & refactor HTTP Cache plugin #8268

Merged
merged 30 commits into from
Jan 23, 2025

Conversation

ardatan
Copy link
Owner

@ardatan ardatan commented Jan 14, 2025

HTTP Cache Plugin

Note: Cache-Control avoids sending requests in a certain TTL but there is no way to invalidate it via mutations as Yoga's response caching plugin do. But the downside of Yoga's approach is, the client/gateway should always send a request to validate the cache result. If Yoga returns 304 Not Modified, the cached response is used. The best solution is to use Gateway's response caching plugin to configure response caching on the gateway level without relying on HTTP headers and benefit from invalidations via mutations.

Composition

Respect other @composeDirective definitions other than Mesh

When some other @composeDirective is used, do not detect it as a Mesh directive;

        extend schema
          @link(
            url: "https://specs.apollo.dev/federation/v2.1"
            import: ["@composeDirective", "@key"]
          )
          @link(
            url: "https://www.apollographql.com/docs/federation/v1/performance/caching/v1.0"
            import: ["@cacheControl"]
          )
          @composeDirective(name: "@cacheControl")
        enum CacheControlScope {
          PUBLIC
          PRIVATE
        }
        directive @cacheControl(
          maxAge: Int
          scope: CacheControlScope
          inheritMaxAge: Boolean
        ) on FIELD_DEFINITION | OBJECT | INTERFACE | UNION

New E2E Test
There is a new E2E test that consists of 3 Federation subgraphs;

  • Authors service uses @cacheControl on Yoga server, and expose it via @composeDirective
  • Books service uses @cacheControl on Apollo Server, and expose it via @composeDirective
  • Comments service set default cache-control header to 5s by default on Apollo Server

Test cases;

So we test @cacheControl directive's behavior with different combinations

** Redis Cache storage improvements**

Milliseconds are important in the caching, instead of EX which expects integers(seconds in float values are not available when you use milliseconds in ttl), we use PX so we can use milliseconds.

Documentation
graphql-hive/console#6395

@ardatan ardatan marked this pull request as draft January 14, 2025 13:28
@ardatan ardatan marked this pull request as ready for review January 14, 2025 13:28
@ardatan ardatan marked this pull request as draft January 14, 2025 13:28
Copy link
Contributor

github-actions bot commented Jan 14, 2025

Apollo Federation Subgraph Compatibility Results

Federation 1 Support Federation 2 Support
_service🟢
@key (single)🟢
@key (multi)🟢
@key (composite)🟢
repeatable @key🟢
@requires🟢
@provides🟢
federated tracing🟢
@link🟢
@shareable🟢
@tag🟢
@override🟢
@inaccessible🟢
@composeDirective🟢
@interfaceObject🟢

Learn more:

Copy link
Contributor

github-actions bot commented Jan 14, 2025

🚀 Snapshot Release (alpha)

The latest changes of this PR are available as alpha on npm (based on the declared changesets):

Package Version Info
@graphql-mesh/cache-cfw-kv 0.104.12-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@graphql-mesh/cache-file 0.103.13-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@graphql-mesh/cache-inmemory-lru 0.0.8-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@graphql-mesh/cache-localforage 0.103.13-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@graphql-mesh/cache-redis 0.103.13-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@graphql-mesh/compose-cli 1.3.6-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@graphql-mesh/fusion-composition 0.7.18-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@graphql-mesh/include 0.2.11-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@graphql-mesh/apollo-link 0.105.13-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@graphql-mesh/cli 0.98.18-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@graphql-mesh/config 0.106.18-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@graphql-mesh/graphql 0.103.13-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@graphql-mesh/grpc 0.107.3-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@graphql-mesh/json-schema 0.108.14-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@graphql-mesh/mongoose 0.103.13-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@graphql-mesh/mysql 0.104.12-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@graphql-mesh/neo4j 0.105.12-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@graphql-mesh/odata 0.105.12-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@graphql-mesh/openapi 0.108.15-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@graphql-mesh/postgraphile 0.103.12-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@graphql-mesh/raml 0.108.13-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@graphql-mesh/soap 0.105.12-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@graphql-mesh/supergraph 0.9.13-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@graphql-mesh/thrift 0.105.12-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@graphql-mesh/tuql 0.104.12-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@graphql-mesh/http 0.105.13-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@graphql-mesh/merger-bare 0.104.15-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@graphql-mesh/merger-stitching 0.104.12-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@graphql-mesh/migrate-config-cli 1.4.10-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@graphql-mesh/runtime 0.105.13-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@graphql-mesh/store 0.103.12-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@graphql-mesh/transform-cache 0.103.13-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@graphql-mesh/transform-encapsulate 0.103.12-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@graphql-mesh/transform-extend 0.103.12-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@graphql-mesh/transform-federation 0.103.12-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@graphql-mesh/transform-filter-schema 0.103.12-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@graphql-mesh/transform-hive 0.103.15-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@graphql-mesh/transform-hoist-field 0.103.13-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@graphql-mesh/transform-naming-convention 0.103.14-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@graphql-mesh/transform-prefix 0.103.14-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@graphql-mesh/transform-prune 0.103.12-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@graphql-mesh/transform-rate-limit 0.103.13-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@graphql-mesh/transform-rename 0.103.13-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@graphql-mesh/transform-replace-field 0.103.13-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@graphql-mesh/transform-resolvers-composition 0.103.12-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@graphql-mesh/transform-transfer-schema 0.103.12-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@graphql-mesh/transform-type-merging 0.103.12-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@graphql-mesh/types 0.103.12-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@graphql-mesh/urql-exchange 0.105.13-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@graphql-mesh/utils 0.103.12-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@omnigraph/grpc 0.2.2-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@omnigraph/json-schema 0.108.13-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@omnigraph/mysql 0.8.12-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@omnigraph/neo4j 0.9.12-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@omnigraph/odata 0.1.12-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@omnigraph/openapi 0.108.15-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@omnigraph/raml 0.108.13-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@omnigraph/soap 0.105.12-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@omnigraph/sqlite 0.7.12-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@omnigraph/thrift 0.8.12-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@graphql-mesh/plugin-deduplicate-request 0.103.12-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@graphql-mesh/plugin-hive 0.103.13-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@graphql-mesh/plugin-http-cache 0.104.0-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@graphql-mesh/plugin-http-details-extensions 0.103.13-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@graphql-mesh/plugin-jit 0.1.12-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@graphql-mesh/plugin-jwt-auth 1.4.2-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@graphql-mesh/plugin-live-query 0.103.12-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@graphql-mesh/plugin-mock 0.103.13-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@graphql-mesh/plugin-newrelic 0.103.12-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@graphql-mesh/plugin-operation-field-permissions 0.103.12-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@graphql-mesh/plugin-operation-headers 1.3.13-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@graphql-mesh/plugin-rate-limit 0.103.12-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@graphql-mesh/plugin-response-cache 0.103.12-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@graphql-mesh/plugin-snapshot 0.103.12-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@graphql-mesh/plugin-statsd 0.103.12-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@graphql-mesh/string-interpolation 0.5.8-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@graphql-mesh/transport-grpc 0.2.2-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@graphql-mesh/transport-mysql 0.8.12-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@graphql-mesh/transport-neo4j 0.8.12-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@graphql-mesh/transport-odata 0.1.12-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@graphql-mesh/transport-rest 0.8.13-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@graphql-mesh/transport-soap 0.8.12-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@graphql-mesh/transport-sqlite 0.8.12-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎
@graphql-mesh/transport-thrift 0.8.12-alpha-20250123141232-8f9ad143dd2118376769ac14e1a0d69af7f15118 npm ↗︎ unpkg ↗︎

Copy link
Contributor

github-actions bot commented Jan 14, 2025

💻 Website Preview

The latest changes are available as preview in: https://3d40e28f.graphql-mesh.pages.dev

@ardatan ardatan marked this pull request as ready for review January 15, 2025 10:37
@ardatan ardatan force-pushed the cache-control-directive-test branch 3 times, most recently from 0a17f00 to 9ed6883 Compare January 15, 2025 12:18
@ardatan ardatan requested a review from enisdenjo January 16, 2025 10:12
@ardatan ardatan changed the title fix(compose): respect other @composeDirective definitions fix(compose): respect other @composeDirective definitions & refactor HTTP Cache plugin Jan 20, 2025
@ardatan ardatan force-pushed the cache-control-directive-test branch from 3bff2de to 4d42fb6 Compare January 20, 2025 14:24
@Urigo
Copy link
Collaborator

Urigo commented Jan 20, 2025

@ardatan is there a reason for these two changes to be combined?

@ardatan ardatan marked this pull request as draft January 20, 2025 18:29
@ardatan ardatan removed the request for review from enisdenjo January 20, 2025 19:11
@ardatan ardatan marked this pull request as ready for review January 20, 2025 19:17
@ardatan
Copy link
Owner Author

ardatan commented Jan 20, 2025

I updated the description, I hope it is more clear right now @Urigo
Sorry I should've converted the PR to a draft while working on it

@ardatan ardatan force-pushed the cache-control-directive-test branch from f1c60a7 to 631ad2d Compare January 23, 2025 12:32
@ardatan ardatan changed the base branch from master to update-deps January 23, 2025 12:45
@ardatan ardatan force-pushed the cache-control-directive-test branch from b4581e7 to 1efb292 Compare January 23, 2025 12:52
@ardatan ardatan force-pushed the cache-control-directive-test branch 2 times, most recently from c671286 to eac33eb Compare January 23, 2025 12:57
Base automatically changed from update-deps to master January 23, 2025 13:25
@ardatan ardatan force-pushed the cache-control-directive-test branch from 859c980 to 64909f0 Compare January 23, 2025 13:27
@ardatan ardatan force-pushed the cache-control-directive-test branch from 5990d6d to bc1e8c1 Compare January 23, 2025 13:34
Copy link
Collaborator

@EmrysMyrddin EmrysMyrddin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed during a call :-) All good for me !
Bothe changes are pretty intrecated, I think it is ok to have both in the same PR for this time.

@ardatan ardatan merged commit f1b5e8e into master Jan 23, 2025
18 checks passed
@ardatan ardatan deleted the cache-control-directive-test branch January 23, 2025 14:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants