Skip to content

Commit 3cc3d77

Browse files
Milinda Diasclaude
authored andcommitted
feat(router): entity caching with L1/L2, shadow mode, and per-request cache controls
Extracted from jensneuse/entity-caching-v2 (PR #2777) — router layer, stacked on the demo PR. Entity cache OTEL/Prometheus metrics are split into the next PR in the stack; this PR contains the cache engine and wiring only. - router/pkg/entitycache: in-memory L1, Redis L2, circuit breaker - router/core: factoryresolver mapping of proto cache config to planner metadata, graph server wiring, per-request cache-control headers, plan generator nil guard - config schema + defaults for entity_caching (metrics opt-in keys land with the metrics PR) - graphql-go-tools bumped to PR #1259 HEAD (resolver/planner side) - router-tests/entity_caching: integration suite consuming the demo module's cachetest subgraphs; compose tool for testdata/config.json Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 9cff599 commit 3cc3d77

52 files changed

Lines changed: 8289 additions & 326 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.PHONY: compose
2+
3+
compose:
4+
go run ./cmd/compose
5+
jq . testdata/config.json > testdata/config.json.tmp
6+
mv testdata/config.json.tmp testdata/config.json
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
composition "github.com/wundergraph/cosmo/composition-go"
8+
)
9+
10+
func main() {
11+
itemsSchema, err := os.ReadFile("../../demo/pkg/subgraphs/cachetest/items/subgraph/schema.graphqls")
12+
if err != nil {
13+
fmt.Fprintf(os.Stderr, "error reading items schema: %v\n", err)
14+
os.Exit(1)
15+
}
16+
detailsSchema, err := os.ReadFile("../../demo/pkg/subgraphs/cachetest/details/subgraph/schema.graphqls")
17+
if err != nil {
18+
fmt.Fprintf(os.Stderr, "error reading details schema: %v\n", err)
19+
os.Exit(1)
20+
}
21+
inventorySchema, err := os.ReadFile("../../demo/pkg/subgraphs/cachetest/inventory/subgraph/schema.graphqls")
22+
if err != nil {
23+
fmt.Fprintf(os.Stderr, "error reading inventory schema: %v\n", err)
24+
os.Exit(1)
25+
}
26+
viewerSchema, err := os.ReadFile("../../demo/pkg/subgraphs/cachetest/viewer/subgraph/schema.graphqls")
27+
if err != nil {
28+
fmt.Fprintf(os.Stderr, "error reading viewer schema: %v\n", err)
29+
os.Exit(1)
30+
}
31+
articlesSchema, err := os.ReadFile("../../demo/pkg/subgraphs/cachetest/articles/subgraph/schema.graphqls")
32+
if err != nil {
33+
fmt.Fprintf(os.Stderr, "error reading articles schema: %v\n", err)
34+
os.Exit(1)
35+
}
36+
articlesMetaSchema, err := os.ReadFile("../../demo/pkg/subgraphs/cachetest/articlesmeta/subgraph/schema.graphqls")
37+
if err != nil {
38+
fmt.Fprintf(os.Stderr, "error reading articlesmeta schema: %v\n", err)
39+
os.Exit(1)
40+
}
41+
42+
result, err := composition.BuildRouterConfiguration(
43+
&composition.Subgraph{
44+
Name: "items",
45+
Schema: string(itemsSchema),
46+
URL: "http://items.entity-cache-test.local/graphql",
47+
},
48+
&composition.Subgraph{
49+
Name: "details",
50+
Schema: string(detailsSchema),
51+
URL: "http://details.entity-cache-test.local/graphql",
52+
},
53+
&composition.Subgraph{
54+
Name: "inventory",
55+
Schema: string(inventorySchema),
56+
URL: "http://inventory.entity-cache-test.local/graphql",
57+
},
58+
&composition.Subgraph{
59+
Name: "viewer",
60+
Schema: string(viewerSchema),
61+
URL: "http://viewer.entity-cache-test.local/graphql",
62+
},
63+
&composition.Subgraph{
64+
Name: "articles",
65+
Schema: string(articlesSchema),
66+
URL: "http://articles.entity-cache-test.local/graphql",
67+
},
68+
&composition.Subgraph{
69+
Name: "articlesmeta",
70+
Schema: string(articlesMetaSchema),
71+
URL: "http://articlesmeta.entity-cache-test.local/graphql",
72+
},
73+
)
74+
if err != nil {
75+
fmt.Fprintf(os.Stderr, "composition error: %v\n", err)
76+
os.Exit(1)
77+
}
78+
79+
if err := os.MkdirAll("testdata", 0o755); err != nil {
80+
fmt.Fprintf(os.Stderr, "error creating testdata dir: %v\n", err)
81+
os.Exit(1)
82+
}
83+
if err := os.WriteFile("testdata/config.json", []byte(result), 0o644); err != nil {
84+
fmt.Fprintf(os.Stderr, "error writing config: %v\n", err)
85+
os.Exit(1)
86+
}
87+
fmt.Printf("config written to testdata/config.json (%d bytes)\n", len(result))
88+
}

0 commit comments

Comments
 (0)