Skip to content

Commit

Permalink
fix: fix merging of response nodes of enum type (#978)
Browse files Browse the repository at this point in the history
  • Loading branch information
devsergiy authored Nov 14, 2024
2 parents b49332d + 99dca41 commit 230d188
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 5 deletions.
108 changes: 106 additions & 2 deletions v2/pkg/engine/postprocess/merge_fields_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ import (
"testing"

"github.com/stretchr/testify/assert"

"github.com/wundergraph/graphql-go-tools/v2/pkg/engine/resolve"
)

func TestMergeFields_Process(t *testing.T) {

runTest := func(in, out resolve.Node) func(t *testing.T) {
runTest := func(in, expected resolve.Node) func(t *testing.T) {
return func(t *testing.T) {
m := &mergeFields{}
m.Process(in)
assert.Equal(t, out, in)
assert.Equal(t, expected, in)
}
}

Expand Down Expand Up @@ -43,6 +44,109 @@ func TestMergeFields_Process(t *testing.T) {
},
))

t.Run("merge enum fields", runTest(
&resolve.Object{
Fields: []*resolve.Field{
{
Name: []byte(`interfaceField`),
Value: &resolve.Object{
Fields: []*resolve.Field{
{
Name: []byte(`enumField`),
Value: &resolve.Enum{
Values: []string{`a`},
InaccessibleValues: []string{},
TypeName: `Enum`,
},
},
},
},
OnTypeNames: [][]byte{[]byte(`A`), []byte(`B`)},
},
{
Name: []byte(`interfaceField`),
Value: &resolve.Object{
Fields: []*resolve.Field{
{
Name: []byte(`stringField`),
Value: &resolve.String{},
},
},
},
OnTypeNames: [][]byte{[]byte(`A`), []byte(`B`)},
},
},
},
&resolve.Object{
Fields: []*resolve.Field{
{
Name: []byte(`interfaceField`),
Value: &resolve.Object{
Fields: []*resolve.Field{
{
Name: []byte(`enumField`),
Value: &resolve.Enum{
Values: []string{`a`},
InaccessibleValues: []string{},
TypeName: `Enum`,
},
ParentOnTypeNames: []resolve.ParentOnTypeNames{
{
Depth: 1,
Names: [][]byte{[]byte(`A`)},
},
},
},
{
Name: []byte(`stringField`),
Value: &resolve.String{},
ParentOnTypeNames: []resolve.ParentOnTypeNames{
{
Depth: 1,
Names: [][]byte{[]byte(`A`)},
},
},
},
},
},
OnTypeNames: [][]byte{[]byte(`A`)},
},
{
Name: []byte(`interfaceField`),
Value: &resolve.Object{
Fields: []*resolve.Field{
{
Name: []byte(`enumField`),
Value: &resolve.Enum{
Values: []string{`a`},
InaccessibleValues: []string{},
TypeName: `Enum`,
},
ParentOnTypeNames: []resolve.ParentOnTypeNames{
{
Depth: 1,
Names: [][]byte{[]byte(`B`)},
},
},
},
{
Name: []byte(`stringField`),
Value: &resolve.String{},
ParentOnTypeNames: []resolve.ParentOnTypeNames{
{
Depth: 1,
Names: [][]byte{[]byte(`B`)},
},
},
},
},
},
OnTypeNames: [][]byte{[]byte(`B`)},
},
},
},
))

t.Run("merge fields at the end of an object reverse", runTest(
&resolve.Object{
Fields: []*resolve.Field{
Expand Down
9 changes: 6 additions & 3 deletions v2/pkg/engine/resolve/node_enum.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ func (_ *Enum) NodeKind() NodeKind {

func (e *Enum) Copy() Node {
return &Enum{
Path: e.Path,
Nullable: e.Nullable,
Export: e.Export,
Path: e.Path,
Nullable: e.Nullable,
Export: e.Export,
TypeName: e.TypeName,
Values: e.Values,
InaccessibleValues: e.InaccessibleValues,
}
}

Expand Down

0 comments on commit 230d188

Please sign in to comment.