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: CodeGen for omit_slice_element_pointers and GetMany Entity Resolvers #2802

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion plugin/federation/federation.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func (f *federation) InjectSourceLate(schema *ast.Schema) *ast.Source {
entityResolverInputDefinitions += fmt.Sprintf("\t%s: %s\n", keyField.Field.ToGo(), keyField.Definition.Type.String())
}
entityResolverInputDefinitions += "}"
resolvers += fmt.Sprintf("\t%s(reps: [%s!]!): [%s]\n", r.ResolverName, r.InputTypeName, e.Name)
resolvers += fmt.Sprintf("\t%s(reps: [%s]!): [%s]\n", r.ResolverName, r.InputTypeName, e.Name)
} else {
resolverArgs := ""
for _, keyField := range r.KeyFields {
Expand Down
44 changes: 44 additions & 0 deletions plugin/federation/federation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,50 @@ func TestCodeGenerationFederation2(t *testing.T) {
require.NoError(t, f.GenerateCode(data))
}

// This test is to ensure that the input arguments are not
// changed when cfg.OmitSliceElementPointers is false OR true
func TestMultiWithOmitSliceElemPointersCfg(t *testing.T) {

staticRepsString := "reps: [HelloByNamesInput]!"
t.Run("OmitSliceElementPointers true", func(t *testing.T) {
f, cfg := load(t, "testdata/multi/multi.yml")
cfg.OmitSliceElementPointers = true
err := f.MutateConfig(cfg)
require.NoError(t, err)
require.Len(t, cfg.Schema.Types["_Entity"].Types, 1)
require.Len(t, f.Entities, 1)

entityGraphqlGenerated := false
for _, source := range cfg.Sources {
if source.Name != "federation/entity.graphql" {
continue
}
entityGraphqlGenerated = true
require.Contains(t, source.Input, staticRepsString)
}
require.True(t, entityGraphqlGenerated)
})

t.Run("OmitSliceElementPointers false", func(t *testing.T) {
f, cfg := load(t, "testdata/multi/multi.yml")
cfg.OmitSliceElementPointers = false
err := f.MutateConfig(cfg)
require.NoError(t, err)
require.Len(t, cfg.Schema.Types["_Entity"].Types, 1)
require.Len(t, f.Entities, 1)

entityGraphqlGenerated := false
for _, source := range cfg.Sources {
if source.Name != "federation/entity.graphql" {
continue
}
entityGraphqlGenerated = true
require.Contains(t, source.Input, staticRepsString)
}
require.True(t, entityGraphqlGenerated)
})
}

func TestInjectSourceLate(t *testing.T) {
_, cfg := load(t, "testdata/allthethings/gqlgen.yml")
entityGraphqlGenerated := false
Expand Down
3 changes: 3 additions & 0 deletions plugin/federation/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ func (r *entityResolver) FindManyMultiHellosByName(ctx context.Context, reps []*
/// <Your code to resolve the list of items>
}
```

**Note:**
If you are using `omit_slice_element_pointers: true` option in your config yaml, your `GetMany` resolver will still generate in the example above the same signature `FindManyMultiHellosByName(ctx context.Context, reps []*generated.ManyMultiHellosByNameInput) ([]*generated.MultiHello, error)`. But all other instances will continue to honor `omit_slice_element_pointers: true`
Loading
Loading