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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
7e2b44b
fix(compose): respect other `@composeDirective` definitions
ardatan Jan 14, 2025
7524f35
Test
ardatan Jan 15, 2025
738da7d
Refactor HTTP Cache plugin
ardatan Jan 20, 2025
138b871
Refactor HTTP Cache plugin
ardatan Jan 20, 2025
b844df2
chore(dependencies): updated changesets for modified dependencies
github-actions[bot] Jan 20, 2025
7eba872
Better typings
ardatan Jan 20, 2025
7b884c6
chore(dependencies): updated changesets for modified dependencies
github-actions[bot] Jan 20, 2025
c1a3f60
Fix resolution
ardatan Jan 20, 2025
b0c0aaa
Fix lockfile
ardatan Jan 20, 2025
5857df8
chore(dependencies): updated changesets for modified dependencies
github-actions[bot] Jan 20, 2025
ba414a4
Modified
ardatan Jan 20, 2025
ec7fa62
Cleanup
ardatan Jan 20, 2025
aedb3aa
Cleaner
ardatan Jan 20, 2025
9db2ccb
Use getHeadersObj just in case
ardatan Jan 20, 2025
8a8603e
Cleaner code
ardatan Jan 20, 2025
56752b0
Timeout
ardatan Jan 20, 2025
b90c7b0
Support ETag of Yoga
ardatan Jan 20, 2025
2f9c50e
More query
ardatan Jan 20, 2025
d723b85
Changeset
ardatan Jan 20, 2025
fab2a66
Faster tests
ardatan Jan 21, 2025
2bde845
Faster tests
ardatan Jan 21, 2025
38b00dd
Remove unnecesary changesets
ardatan Jan 23, 2025
08eedb0
Less dif
ardatan Jan 23, 2025
fc906cd
Hmm
ardatan Jan 23, 2025
70b5940
Less dif
ardatan Jan 23, 2025
64909f0
Less diff
ardatan Jan 23, 2025
bc1e8c1
..
ardatan Jan 23, 2025
793f1bb
chore(dependencies): updated changesets for modified dependencies
github-actions[bot] Jan 23, 2025
c4aec89
..
ardatan Jan 23, 2025
8f9ad14
Cache storage changesets
ardatan Jan 23, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@graphql-mesh/plugin-http-cache": patch
---
dependencies updates:
- Updated dependency [`http-cache-semantics@^4.1.1` ↗︎](https://www.npmjs.com/package/http-cache-semantics/v/4.1.1) (from `4.1.1`, in `dependencies`)
6 changes: 6 additions & 0 deletions .changeset/fast-cars-appear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@graphql-mesh/plugin-http-cache': minor
---

- Refactor the plugin, and add `policyOptions` to configure HTTP caching mechanism
- Support [ETag](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/ETag) and [Last-Modified](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Last-Modified) headers
5 changes: 5 additions & 0 deletions .changeset/fifty-hats-begin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-mesh/cache-redis': patch
---

Use `PX` instead of `EX` to handle milliseconds as TTL
5 changes: 5 additions & 0 deletions .changeset/perfect-lions-appear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-mesh/fusion-composition': patch
---

Respect other `@composeDirective` definitions other than Mesh
5 changes: 5 additions & 0 deletions .changeset/twenty-games-raise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-mesh/cache-inmemory-lru': patch
---

Use TTL only if it is valid
224 changes: 224 additions & 0 deletions e2e/cache-control/__snapshots__/cache-control.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Cache Control Apollo Rover composes 1`] = `
"schema
@link(url: "https://specs.apollo.dev/link/v1.0")
@link(url: "https://specs.apollo.dev/join/v0.3", for: EXECUTION)
@link(url: "https://www.apollographql.com/docs/federation/v1/performance/caching/v1.0", import: ["@cacheControl"])
{
query: Query
}

directive @cacheControl(maxAge: Int, scope: CacheControlScope, inheritMaxAge: Boolean) on FIELD_DEFINITION | OBJECT | INTERFACE | UNION

directive @join__enumValue(graph: join__Graph!) repeatable on ENUM_VALUE

directive @join__field(graph: join__Graph, requires: join__FieldSet, provides: join__FieldSet, type: String, external: Boolean, override: String, usedOverridden: Boolean) repeatable on FIELD_DEFINITION | INPUT_FIELD_DEFINITION

directive @join__graph(name: String!, url: String!) on ENUM_VALUE

directive @join__implements(graph: join__Graph!, interface: String!) repeatable on OBJECT | INTERFACE

directive @join__type(graph: join__Graph!, key: join__FieldSet, extension: Boolean! = false, resolvable: Boolean! = true, isInterfaceObject: Boolean! = false) repeatable on OBJECT | INTERFACE | UNION | ENUM | INPUT_OBJECT | SCALAR

directive @join__unionMember(graph: join__Graph!, member: String!) repeatable on UNION

directive @link(url: String, as: String, for: link__Purpose, import: [link__Import]) repeatable on SCHEMA

type Author
@join__type(graph: AUTHORS, key: "id")
@join__type(graph: BOOKS, key: "id", extension: true)
@cacheControl(maxAge: 10)
{
id: ID!
name: String! @join__field(graph: AUTHORS)
age: Int @join__field(graph: AUTHORS)
books: [Book] @join__field(graph: BOOKS)
}

type Book
@join__type(graph: BOOKS, key: "id")
@join__type(graph: COMMENTS, key: "id", extension: true)
@cacheControl(maxAge: 10)
{
id: ID!
title: String! @join__field(graph: BOOKS)
author: Author! @join__field(graph: BOOKS)
comments: [Comment] @join__field(graph: COMMENTS)
}

enum CacheControlScope
@join__type(graph: AUTHORS)
@join__type(graph: BOOKS)
{
PUBLIC @join__enumValue(graph: AUTHORS) @join__enumValue(graph: BOOKS)
PRIVATE @join__enumValue(graph: AUTHORS) @join__enumValue(graph: BOOKS)
}

type Comment
@join__type(graph: COMMENTS, key: "id")
{
id: ID!
content: String!
book: Book!
}

scalar join__FieldSet

enum join__Graph {
AUTHORS @join__graph(name: "authors", url: "http://localhost:<authors_port>/graphql")
BOOKS @join__graph(name: "books", url: "http://localhost:<books_port>/graphql")
COMMENTS @join__graph(name: "comments", url: "http://localhost:<comments_port>/graphql")
}

scalar link__Import

enum link__Purpose {
"""
\`SECURITY\` features provide metadata necessary to securely resolve fields.
"""
SECURITY

"""
\`EXECUTION\` features provide metadata necessary for operation execution.
"""
EXECUTION
}

type Query
@join__type(graph: AUTHORS)
@join__type(graph: BOOKS)
@join__type(graph: COMMENTS)
{
authors: [Author] @join__field(graph: AUTHORS)
author(id: ID!): Author @join__field(graph: AUTHORS)
books: [Book] @join__field(graph: BOOKS)
book(id: ID!): Book @join__field(graph: BOOKS)
comments: [Comment] @join__field(graph: COMMENTS)
}"
`;

exports[`Cache Control Mesh Compose composes 1`] = `
"
schema
@link(url: "https://specs.apollo.dev/link/v1.0")
@link(url: "https://specs.apollo.dev/join/v0.3", for: EXECUTION)





@link(
url: "https://www.apollographql.com/docs/federation/v1/performance/caching/v1.0"
import: ["@cacheControl"]
)
{
query: Query


}


directive @join__enumValue(graph: join__Graph!) repeatable on ENUM_VALUE

directive @join__field(
graph: join__Graph
requires: join__FieldSet
provides: join__FieldSet
type: String
external: Boolean
override: String
usedOverridden: Boolean
) repeatable on FIELD_DEFINITION | INPUT_FIELD_DEFINITION

directive @join__graph(name: String!, url: String!) on ENUM_VALUE

directive @join__implements(
graph: join__Graph!
interface: String!
) repeatable on OBJECT | INTERFACE

directive @join__type(
graph: join__Graph!
key: join__FieldSet
extension: Boolean! = false
resolvable: Boolean! = true
isInterfaceObject: Boolean! = false
) repeatable on OBJECT | INTERFACE | UNION | ENUM | INPUT_OBJECT | SCALAR

directive @join__unionMember(graph: join__Graph!, member: String!) repeatable on UNION

scalar join__FieldSet


directive @link(
url: String
as: String
for: link__Purpose
import: [link__Import]
) repeatable on SCHEMA

scalar link__Import

enum link__Purpose {
"""
\`SECURITY\` features provide metadata necessary to securely resolve fields.
"""
SECURITY

"""
\`EXECUTION\` features provide metadata necessary for operation execution.
"""
EXECUTION
}







enum join__Graph {
AUTHORS @join__graph(name: "authors", url: "http://localhost:<authors_port>/graphql")
BOOKS @join__graph(name: "books", url: "http://localhost:<books_port>/graphql")
COMMENTS @join__graph(name: "comments", url: "http://localhost:<comments_port>/graphql")
}

directive @cacheControl(maxAge: Int, scope: CacheControlScope, inheritMaxAge: Boolean) on FIELD_DEFINITION | OBJECT | INTERFACE | UNION

scalar TransportOptions @join__type(graph: AUTHORS) @join__type(graph: BOOKS) @join__type(graph: COMMENTS)

type Author @cacheControl(maxAge: 10) @join__type(graph: AUTHORS, key: "id") @join__type(graph: BOOKS, key: "id", extension: true) {
id: ID!
name: String! @join__field(graph: AUTHORS)
age: Int @join__field(graph: AUTHORS)
books: [Book] @join__field(graph: BOOKS)
}

type Query @join__type(graph: AUTHORS) @join__type(graph: BOOKS) @join__type(graph: COMMENTS) {
authors: [Author] @join__field(graph: AUTHORS)
author(id: ID!) : Author @join__field(graph: AUTHORS)
books: [Book] @join__field(graph: BOOKS)
book(id: ID!) : Book @join__field(graph: BOOKS)
comments: [Comment] @join__field(graph: COMMENTS)
}

type Book @cacheControl(maxAge: 10) @join__type(graph: BOOKS, key: "id") @join__type(graph: COMMENTS, key: "id", extension: true) {
id: ID!
title: String! @join__field(graph: BOOKS)
author: Author! @join__field(graph: BOOKS)
comments: [Comment] @join__field(graph: COMMENTS)
}

type Comment @join__type(graph: COMMENTS, key: "id") {
id: ID!
content: String!
book: Book!
}

enum CacheControlScope @join__type(graph: AUTHORS) @join__type(graph: BOOKS) {
PUBLIC @join__enumValue(graph: AUTHORS) @join__enumValue(graph: BOOKS)
PRIVATE @join__enumValue(graph: AUTHORS) @join__enumValue(graph: BOOKS)
}
"
`;
Loading
Loading