From afc01ccdeb0ef9f69466c8f1843dbf4e48d54396 Mon Sep 17 00:00:00 2001 From: MiguelCastillo Date: Sat, 13 Nov 2021 12:12:45 -0500 Subject: [PATCH] Cleaning up extra return in federation generated code In PR 1709, I introduced GetMany semantics for resolving federated entities. But I left a couple of extra return statements in the generated code that are not necessary. So Im just cleaning those up here. Also added `go:generate` in federation entity resolver tests to make it simpler to test. To test: ``` go generate ./... && cd example/ && go generate ./... && cd .. go test -race ./... && cd example && go test -race ./... && cd .. ``` --- example/federation/accounts/graph/generated/federation.go | 4 ---- example/federation/products/graph/generated/federation.go | 4 ---- example/federation/reviews/graph/generated/federation.go | 4 ---- plugin/federation/federation.gotpl | 7 ++----- plugin/federation/federation_entityresolver_test.go | 1 + plugin/federation/readme.md | 4 ++-- .../testdata/entityresolver/generated/federation.go | 8 ++++---- 7 files changed, 9 insertions(+), 23 deletions(-) diff --git a/example/federation/accounts/graph/generated/federation.go b/example/federation/accounts/graph/generated/federation.go index 11a6382fcb8..870c0253606 100644 --- a/example/federation/accounts/graph/generated/federation.go +++ b/example/federation/accounts/graph/generated/federation.go @@ -125,8 +125,6 @@ func (ec *executionContext) __resolve_entities(ctx context.Context, representati default: return errors.New("unknown type: " + typeName) } - - return nil } resolveEntityGroup := func(typeName string, reps []map[string]interface{}, idx []int) { @@ -176,6 +174,4 @@ func (ec *executionContext) __resolve_entities(ctx context.Context, representati g.Wait() return list } - - return list } diff --git a/example/federation/products/graph/generated/federation.go b/example/federation/products/graph/generated/federation.go index 0e416ab1a86..3d3fbf718c2 100644 --- a/example/federation/products/graph/generated/federation.go +++ b/example/federation/products/graph/generated/federation.go @@ -129,8 +129,6 @@ func (ec *executionContext) __resolve_entities(ctx context.Context, representati default: return errors.New("unknown type: " + typeName) } - - return nil } resolveEntityGroup := func(typeName string, reps []map[string]interface{}, idx []int) { @@ -180,6 +178,4 @@ func (ec *executionContext) __resolve_entities(ctx context.Context, representati g.Wait() return list } - - return list } diff --git a/example/federation/reviews/graph/generated/federation.go b/example/federation/reviews/graph/generated/federation.go index 32389bc56a9..2f2ed3c9493 100644 --- a/example/federation/reviews/graph/generated/federation.go +++ b/example/federation/reviews/graph/generated/federation.go @@ -139,8 +139,6 @@ func (ec *executionContext) __resolve_entities(ctx context.Context, representati default: return errors.New("unknown type: " + typeName) } - - return nil } resolveEntityGroup := func(typeName string, reps []map[string]interface{}, idx []int) { @@ -190,6 +188,4 @@ func (ec *executionContext) __resolve_entities(ctx context.Context, representati g.Wait() return list } - - return list } diff --git a/plugin/federation/federation.gotpl b/plugin/federation/federation.gotpl index e888acd7d94..7c60840ed13 100644 --- a/plugin/federation/federation.gotpl +++ b/plugin/federation/federation.gotpl @@ -160,14 +160,13 @@ func (ec *executionContext) __resolve_entities(ctx context.Context, representati {{- end -}} list[idx[i]] = entity } + return nil {{ end }} - {{- end }} + {{ end }} {{- end }} default: return errors.New("unknown type: "+typeName) } - - return nil } resolveEntityGroup := func(typeName string, reps []map[string]interface{}, idx []int) { @@ -217,7 +216,5 @@ func (ec *executionContext) __resolve_entities(ctx context.Context, representati g.Wait() return list } - - return list } {{end}} diff --git a/plugin/federation/federation_entityresolver_test.go b/plugin/federation/federation_entityresolver_test.go index cc0158e6ddb..2a3ed83c211 100644 --- a/plugin/federation/federation_entityresolver_test.go +++ b/plugin/federation/federation_entityresolver_test.go @@ -1,3 +1,4 @@ +//go:generate go run ../../testdata/gqlgen.go -config testdata/entityresolver/gqlgen.yml package federation import ( diff --git a/plugin/federation/readme.md b/plugin/federation/readme.md index e2156e668f6..4333ed47979 100644 --- a/plugin/federation/readme.md +++ b/plugin/federation/readme.md @@ -9,7 +9,7 @@ There are several different tests. Some will process the configuration file dire Running entity resolver tests. 1. Go to `plugin/federation` -2. Run the command `go run github.com/99designs/gqlgen --config testdata/entityresolver/gqlgen.yml` +2. Run the command `go generate` 3. Run the tests with `go test ./...`. # Architecture @@ -33,7 +33,7 @@ That allows the federation plugin to generate `GetMany` resolver function that c From that entity type, the resolver function would be ``` -func (r *entityResolver) FindManyMultiHellosByName(ctx context.Context, reps []*generated.EntityResolverfindManyMultiHellosByNameInput) ([]*generated.MultiHello, error) { +func (r *entityResolver) FindManyMultiHellosByName(ctx context.Context, reps []*generated.ManyMultiHellosByNameInput) ([]*generated.MultiHello, error) { /// } ``` diff --git a/plugin/federation/testdata/entityresolver/generated/federation.go b/plugin/federation/testdata/entityresolver/generated/federation.go index ce813f278e0..dacd3c04fee 100644 --- a/plugin/federation/testdata/entityresolver/generated/federation.go +++ b/plugin/federation/testdata/entityresolver/generated/federation.go @@ -179,6 +179,7 @@ func (ec *executionContext) __resolve_entities(ctx context.Context, representati }() switch typeName { + case "MultiHello": _reps := make([]*MultiHelloByNamesInput, len(reps)) @@ -201,6 +202,8 @@ func (ec *executionContext) __resolve_entities(ctx context.Context, representati for i, entity := range entities { list[idx[i]] = entity } + return nil + case "MultiHelloWithError": _reps := make([]*MultiHelloWithErrorByNamesInput, len(reps)) @@ -223,12 +226,11 @@ func (ec *executionContext) __resolve_entities(ctx context.Context, representati for i, entity := range entities { list[idx[i]] = entity } + return nil default: return errors.New("unknown type: " + typeName) } - - return nil } resolveEntityGroup := func(typeName string, reps []map[string]interface{}, idx []int) { @@ -278,6 +280,4 @@ func (ec *executionContext) __resolve_entities(ctx context.Context, representati g.Wait() return list } - - return list }