Skip to content

Commit 6936d4d

Browse files
authored
chore(demo): fix code generation for cost directives (#2667)
Include new directives into the schemas to make gqlgen happy. Verify generation in the demo and router-tests.
1 parent 771c18a commit 6936d4d

File tree

15 files changed

+172
-40
lines changed

15 files changed

+172
-40
lines changed

.github/workflows/demo-ci.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Demo CI
2+
on:
3+
pull_request:
4+
paths:
5+
- "demo/**/*"
6+
- ".github/workflows/demo-ci.yaml"
7+
8+
concurrency:
9+
group: ${{github.workflow}}-${{github.head_ref}}
10+
cancel-in-progress: true
11+
12+
env:
13+
CI: true
14+
15+
jobs:
16+
build_test:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: actions/checkout@v4
20+
- uses: ./.github/actions/go
21+
22+
- name: Generate code
23+
working-directory: demo
24+
run: make generate
25+
26+
- uses: ./.github/actions/git-dirty-check
27+
with:
28+
package-name: demo

.github/workflows/router-ci.yaml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,13 @@ jobs:
6363
with:
6464
bun-version: 1.2.15
6565

66-
- name: Generate code
66+
- name: Generate Go code
6767
run: make generate-go
6868

69+
- name: Generate test configs from demo
70+
working-directory: ./router-tests
71+
run: ./update-config-no-edg.sh
72+
6973
- uses: ./.github/actions/git-dirty-check
7074
with:
7175
package-name: router
@@ -155,11 +159,16 @@ jobs:
155159
with:
156160
bun-version: 1.2.15
157161

158-
- name: Generate code
162+
- name: Generate Go code
159163
run: make generate-go
160164

161-
- name: Check if git is not dirty after generating files
162-
run: git diff --no-ext-diff --exit-code
165+
- name: Generate test configs from demo
166+
working-directory: ./router-tests
167+
run: ./update-config-no-edg.sh
168+
169+
- uses: ./.github/actions/git-dirty-check
170+
with:
171+
package-name: router
163172

164173
- name: Install dependencies
165174
working-directory: ./router

demo/go.mod

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ require (
1111
github.com/rs/cors v1.11.0
1212
github.com/vektah/gqlparser/v2 v2.5.30
1313
github.com/wundergraph/cosmo/composition-go v0.0.0-20250820135159-bf8852195d3f
14-
github.com/wundergraph/cosmo/router v0.0.0-20260213130455-6e3277e7b850
15-
github.com/wundergraph/cosmo/router-tests v0.0.0-20260213130455-6e3277e7b850
14+
github.com/wundergraph/cosmo/router v0.0.0-20260318232543-0e5fa811a191
15+
github.com/wundergraph/cosmo/router-tests v0.0.0-20260318232543-0e5fa811a191
1616
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.58.0
1717
go.opentelemetry.io/otel v1.36.0
1818
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.33.0
@@ -23,7 +23,8 @@ require (
2323
)
2424

2525
require (
26-
connectrpc.com/connect v1.16.2 // indirect
26+
connectrpc.com/connect v1.19.1 // indirect
27+
connectrpc.com/vanguard v0.3.0 // indirect
2728
github.com/KimMachineGun/automemlimit v0.6.1 // indirect
2829
github.com/MicahParks/jwkset v0.11.0 // indirect
2930
github.com/MicahParks/keyfunc/v3 v3.6.2 // indirect
@@ -145,10 +146,10 @@ require (
145146
github.com/urfave/cli/v2 v2.27.7 // indirect
146147
github.com/vbatts/tar-split v0.12.1 // indirect
147148
github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect
148-
github.com/wundergraph/astjson v1.0.0 // indirect
149+
github.com/wundergraph/astjson v1.1.0 // indirect
149150
github.com/wundergraph/cosmo/demo/pkg/subgraphs/projects v0.0.0-20250715110703-10f2e5f9c79e // indirect
150151
github.com/wundergraph/go-arena v1.1.0 // indirect
151-
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.248 // indirect
152+
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.265 // indirect
152153
github.com/xrash/smetrics v0.0.0-20250705151800-55b8f293f342 // indirect
153154
github.com/yosida95/uritemplate/v3 v3.0.2 // indirect
154155
github.com/yusufpapurcu/wmi v1.2.4 // indirect

demo/go.sum

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
connectrpc.com/connect v1.16.2 h1:ybd6y+ls7GOlb7Bh5C8+ghA6SvCBajHwxssO2CGFjqE=
2-
connectrpc.com/connect v1.16.2/go.mod h1:n2kgwskMHXC+lVqb18wngEpF95ldBHXjZYJussz5FRc=
1+
connectrpc.com/connect v1.19.1 h1:R5M57z05+90EfEvCY1b7hBxDVOUl45PrtXtAV2fOC14=
2+
connectrpc.com/connect v1.19.1/go.mod h1:tN20fjdGlewnSFeZxLKb0xwIZ6ozc3OQs2hTXy4du9w=
3+
connectrpc.com/vanguard v0.3.0 h1:prUKFm8rYDwvpvnOSoqdUowPMK0tRA0pbSrQoMd6Zng=
4+
connectrpc.com/vanguard v0.3.0/go.mod h1:nxQ7+N6qhBiQczqGwdTw4oCqx1rDryIt20cEdECqToM=
35
github.com/99designs/gqlgen v0.17.76 h1:YsJBcfACWmXWU2t1yCjoGdOmqcTfOFpjbLAE443fmYI=
46
github.com/99designs/gqlgen v0.17.76/go.mod h1:miiU+PkAnTIDKMQ1BseUOIVeQHoiwYDZGCswoxl7xec=
57
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
@@ -187,8 +189,8 @@ github.com/jensneuse/byte-template v0.0.0-20231025215717-69252eb3ed56 h1:wo26fh6
187189
github.com/jensneuse/byte-template v0.0.0-20231025215717-69252eb3ed56/go.mod h1:0D5r/VSW6D/o65rKLL9xk7sZxL2+oku2HvFPYeIMFr4=
188190
github.com/jensneuse/diffview v1.0.0 h1:4b6FQJ7y3295JUHU3tRko6euyEboL825ZsXeZZM47Z4=
189191
github.com/jensneuse/diffview v1.0.0/go.mod h1:i6IacuD8LnEaPuiyzMHA+Wfz5mAuycMOf3R/orUY9y4=
190-
github.com/jhump/protoreflect v1.15.1 h1:HUMERORf3I3ZdX05WaQ6MIpd/NJ434hTp5YiKgfCL6c=
191-
github.com/jhump/protoreflect v1.15.1/go.mod h1:jD/2GMKKE6OqX8qTjhADU1e6DShO+gavG9e0Q693nKo=
192+
github.com/jhump/protoreflect v1.17.0 h1:qOEr613fac2lOuTgWN4tPAtLL7fUSbuJL5X5XumQh94=
193+
github.com/jhump/protoreflect v1.17.0/go.mod h1:h9+vUUL38jiBzck8ck+6G/aeMX8Z4QUY/NiJPwPNi+8=
192194
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
193195
github.com/josharian/native v1.1.0 h1:uuaP0hAbW7Y4l0ZRQ6C9zfb7Mg1mbFKry/xzDAfmtLA=
194196
github.com/josharian/native v1.1.0/go.mod h1:7X/raswPFr05uY3HiLlYeyQntB6OO7E/d2Cu7qoaN2w=
@@ -371,20 +373,20 @@ github.com/vektah/gqlparser/v2 v2.5.30 h1:EqLwGAFLIzt1wpx1IPpY67DwUujF1OfzgEyDsL
371373
github.com/vektah/gqlparser/v2 v2.5.30/go.mod h1:D1/VCZtV3LPnQrcPBeR/q5jkSQIPti0uYCP/RI0gIeo=
372374
github.com/wk8/go-ordered-map/v2 v2.1.8 h1:5h/BUHu93oj4gIdvHHHGsScSTMijfx5PeYkE/fJgbpc=
373375
github.com/wk8/go-ordered-map/v2 v2.1.8/go.mod h1:5nJHM5DyteebpVlHnWMV0rPz6Zp7+xBAnxjb1X5vnTw=
374-
github.com/wundergraph/astjson v1.0.0 h1:rETLJuQkMWWW03HCF6WBttEBOu8gi5vznj5KEUPVV2Q=
375-
github.com/wundergraph/astjson v1.0.0/go.mod h1:h12D/dxxnedtLzsKyBLK7/Oe4TAoGpRVC9nDpDrZSWw=
376+
github.com/wundergraph/astjson v1.1.0 h1:xORDosrZ87zQFJwNGe/HIHXqzpdHOFmqWgykCLVL040=
377+
github.com/wundergraph/astjson v1.1.0/go.mod h1:h12D/dxxnedtLzsKyBLK7/Oe4TAoGpRVC9nDpDrZSWw=
376378
github.com/wundergraph/cosmo/composition-go v0.0.0-20250820135159-bf8852195d3f h1:TjxywtqT+D6Qa/WGg1Vqn4ogT6P7M+iuUxPgDds1/kU=
377379
github.com/wundergraph/cosmo/composition-go v0.0.0-20250820135159-bf8852195d3f/go.mod h1:S3y/4/28Iut0SHMbmfXXa/6qyP55BA2rS4K3VI8A4Pg=
378380
github.com/wundergraph/cosmo/demo/pkg/subgraphs/projects v0.0.0-20250715110703-10f2e5f9c79e h1:VdJNlsiyWYxJzAD3jEe+DAQdzxkf9btD8qQNYNU+xQU=
379381
github.com/wundergraph/cosmo/demo/pkg/subgraphs/projects v0.0.0-20250715110703-10f2e5f9c79e/go.mod h1:WZ0yBeaDSGHqDMcQrP1JRYgCj9atF7ORXF8srnd2Sro=
380-
github.com/wundergraph/cosmo/router v0.0.0-20260213130455-6e3277e7b850 h1:KpamF+1Vo3Dm8gcayYXTPZuKgPw/zVgJAI/NeODVVeU=
381-
github.com/wundergraph/cosmo/router v0.0.0-20260213130455-6e3277e7b850/go.mod h1:We+sYVVSnWyylJRHpELaR0GOZndk1UI4gtf2zceZEmA=
382-
github.com/wundergraph/cosmo/router-tests v0.0.0-20260213130455-6e3277e7b850 h1:ddKb9MX85UdRTrLzzYFnob2dU0VHhKqNSwUa0UEr1cs=
383-
github.com/wundergraph/cosmo/router-tests v0.0.0-20260213130455-6e3277e7b850/go.mod h1:T5l+RrKg83m7G5OLJeHO9fEJT3zUeZ/VfKf+k98Ol0g=
382+
github.com/wundergraph/cosmo/router v0.0.0-20260318232543-0e5fa811a191 h1:PCEyCEchpG/2IY4uH0tizZQlqSKuspv4lHtiFbl+fZM=
383+
github.com/wundergraph/cosmo/router v0.0.0-20260318232543-0e5fa811a191/go.mod h1:YawmJF/Oue/8PCCtP7x2smoRsKsL6h/wpjje5gqSOmw=
384+
github.com/wundergraph/cosmo/router-tests v0.0.0-20260318232543-0e5fa811a191 h1:q4T4N463s+mhf7v3mEU4zW71qX1tBeT/IwD29oQ/wPM=
385+
github.com/wundergraph/cosmo/router-tests v0.0.0-20260318232543-0e5fa811a191/go.mod h1:x/MoiTDyaRkTrfh5EMJTSzGLsB1eZ8mI/zrZgRRAvhA=
384386
github.com/wundergraph/go-arena v1.1.0 h1:9+wSRkJAkA2vbYHp6s8tEGhPViRGQNGXqPHT0QzhdIc=
385387
github.com/wundergraph/go-arena v1.1.0/go.mod h1:ROOysEHWJjLQ8FSfNxZCziagb7Qw2nXY3/vgKRh7eWw=
386-
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.248 h1:+6Byi9AMVT2eP6hJhNH6unRXjTtkzVs3fc/2XExbJpY=
387-
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.248/go.mod h1:MFbY0QI8ncF60DHs7yyyiyyhWyld0WE1JokiyTVY8j4=
388+
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.265 h1:KVmojt3oH13VX8Yr8NZ+fuOiruLyznderHITJs1MyWE=
389+
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.265/go.mod h1:HjTAO/cuICpu31IfHY9qmSPygx6Gza7Wt9hTSReTI+A=
388390
github.com/xrash/smetrics v0.0.0-20250705151800-55b8f293f342 h1:FnBeRrxr7OU4VvAzt5X7s6266i6cSVkkFPS0TuXWbIg=
389391
github.com/xrash/smetrics v0.0.0-20250705151800-55b8f293f342/go.mod h1:Ohn+xnUBiLI6FVj/9LpzZWtj1/D6lUovWYBkxHVV3aM=
390392
github.com/yosida95/uritemplate/v3 v3.0.2 h1:Ed3Oyj9yrmi9087+NczuL5BwkIc4wvTb5zIM+UJPGz4=

demo/pkg/subgraphs/employees/gqlgen.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ resolver:
2626
package: subgraph
2727

2828
directives:
29+
cost:
30+
skip_runtime: true
31+
listSize:
32+
skip_runtime: true
2933
openfed__requireFetchReasons:
3034
skip_runtime: true
3135

demo/pkg/subgraphs/employees/subgraph/generated/generated.go

Lines changed: 20 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

demo/pkg/subgraphs/employees/subgraph/schema.graphqls

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,21 @@ extend schema
1818
]
1919
)
2020

21+
directive @cost(weight: Int!) on
22+
| ARGUMENT_DEFINITION
23+
| ENUM
24+
| FIELD_DEFINITION
25+
| INPUT_FIELD_DEFINITION
26+
| OBJECT
27+
| SCALAR
28+
29+
directive @listSize(
30+
assumedSize: Int,
31+
slicingArguments: [String!],
32+
sizedFields: [String!],
33+
requireOneSlicingArgument: Boolean = true
34+
) on FIELD_DEFINITION
35+
2136
directive @goField(
2237
forceResolver: Boolean
2338
name: String

demo/pkg/subgraphs/products/gqlgen.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ resolver:
2525
dir: subgraph
2626
package: subgraph
2727

28+
directives:
29+
cost:
30+
skip_runtime: true
31+
listSize:
32+
skip_runtime: true
33+
2834
# Optional: turn on use `gqlgen:"fieldName"` tags in your models
2935
# struct_tag: json
3036

demo/pkg/subgraphs/products/subgraph/generated/generated.go

Lines changed: 37 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

demo/pkg/subgraphs/products/subgraph/schema.graphqls

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
11
extend schema
22
@link(url: "https://specs.apollo.dev/federation/v2.5", import: ["@authenticated", "@composeDirective", "@external", "@extends", "@inaccessible", "@interfaceObject", "@override", "@provides", "@key", "@requires", "@requiresScopes", "@shareable", "@tag"])
33

4+
directive @cost(weight: Int!) on
5+
| ARGUMENT_DEFINITION
6+
| ENUM
7+
| FIELD_DEFINITION
8+
| INPUT_FIELD_DEFINITION
9+
| OBJECT
10+
| SCALAR
11+
12+
directive @listSize(
13+
assumedSize: Int,
14+
slicingArguments: [String!],
15+
sizedFields: [String!],
16+
requireOneSlicingArgument: Boolean = true
17+
) on FIELD_DEFINITION
18+
419
schema {
520
query: Queries
621
mutation: Mutation

0 commit comments

Comments
 (0)