Skip to content

Commit cfebc16

Browse files
authored
fix: refactor CoordinateDependencies, FetchReasons (#1293)
Move them into the "FetchInfo" struct. That struct is ideal for storing derived data for a Fetch and passing to the later stages of the engine. Add the BuildFetchReasons option to the planner, that allows other parts to enable building the FetchReason list.
1 parent 37c9582 commit cfebc16

18 files changed

Lines changed: 462 additions & 288 deletions

execution/Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ test-quick:
1313
update-fixtures:
1414
GOLDIE_UPDATE=1 go test -count=1 ./engine/...
1515

16+
# golangci-lint will find the config file in the root dir of the repo.
1617
.PHONY: format
1718
format:
18-
golangci-lint fmt --config ../.golangci.yml
19+
golangci-lint fmt
1920

2021
lint:
21-
golangci-lint run --config ../.golangci.yml .
22+
golangci-lint run
2223

2324
.PHONY: prepare-merge
2425
prepare-merge: format test

execution/engine/execution_engine_test.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,12 @@ func withValueCompletion() executionTestOptions {
231231
}
232232
}
233233

234+
func withFetchReasons() executionTestOptions {
235+
return func(options *_executionTestOptions) {
236+
options.propagateFetchReasons = true
237+
}
238+
}
239+
234240
func TestExecutionEngine_Execute(t *testing.T) {
235241
run := func(testCase ExecutionEngineTestCase, withError bool, expectedErrorMessage string, options ...executionTestOptions) func(t *testing.T) {
236242
t.Helper()
@@ -262,6 +268,7 @@ func TestExecutionEngine_Execute(t *testing.T) {
262268
for _, option := range options {
263269
option(&opts)
264270
}
271+
engineConf.plannerConfig.BuildFetchReasons = opts.propagateFetchReasons
265272
engine, err := NewExecutionEngine(ctx, abstractlogger.Noop{}, engineConf, resolve.ResolverOptions{
266273
MaxConcurrency: 1024,
267274
ResolvableOptions: opts.resolvableOptions,
@@ -827,7 +834,7 @@ func TestExecutionEngine_Execute(t *testing.T) {
827834
},
828835
))
829836

830-
t.Run("execute simple hero operation with propagating to subgraphs reason for fields being requested", runWithoutError(
837+
t.Run("execute simple hero operation with propagating to subgraphs fetch reasons", runWithoutError(
831838
ExecutionEngineTestCase{
832839
schema: graphql.StarwarsSchema(t),
833840
operation: graphql.LoadStarWarsQuery(starwars.FileSimpleHeroQuery, nil),
@@ -875,9 +882,7 @@ func TestExecutionEngine_Execute(t *testing.T) {
875882
fields: []plan.FieldConfiguration{},
876883
expectedResponse: `{"data":{"hero":{"name":"Luke Skywalker"}}}`,
877884
},
878-
func(eto *_executionTestOptions) {
879-
eto.propagateFetchReasons = true
880-
},
885+
withFetchReasons(),
881886
))
882887

883888
t.Run("execute simple hero operation with graphql data source and empty errors list", runWithoutError(
@@ -4539,9 +4544,7 @@ func TestExecutionEngine_Execute(t *testing.T) {
45394544
dataSources: makeDataSource(t, true),
45404545
expectedResponse: `{"data":{"accounts":[{"some":{"title":"User1"}},{"some":{"__typename":"User","id":"2"}},{"some":{"title":"User3"}}]}}`,
45414546
},
4542-
func(eto *_executionTestOptions) {
4543-
eto.propagateFetchReasons = true
4544-
},
4547+
withFetchReasons(),
45454548
))
45464549
})
45474550
}

go.work

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
go 1.25
22

3-
toolchain go1.25
3+
toolchain go1.25.1
44

55
use (
66
// v1

v2/Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@ test-quick:
1313
update-fixtures:
1414
GOLDIE_UPDATE=1 go test -count=1 ./pkg/...
1515

16+
# golangci-lint will find the config file in the root dir of the repo.
1617
.PHONY: format
1718
format:
18-
golangci-lint fmt --config ../.golangci.yml
19+
golangci-lint fmt
1920

2021
.PHONY: lint
2122
lint:
22-
golangci-lint run --config ../.golangci.yml .
23+
golangci-lint run
2324
cd ../execution && make lint
2425

2526
.PHONY: prepare-merge

0 commit comments

Comments
 (0)