-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #843: Bind to embedded struct method or field
- Loading branch information
1 parent
1172128
commit a745dc7
Showing
8 changed files
with
492 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package testserver | ||
|
||
// EmbeddedCase1 model | ||
type EmbeddedCase1 struct { | ||
Empty | ||
*ExportedEmbeddedPointerAfterInterface | ||
} | ||
|
||
// Empty interface | ||
type Empty interface{} | ||
|
||
// ExportedEmbeddedPointerAfterInterface model | ||
type ExportedEmbeddedPointerAfterInterface struct{} | ||
|
||
// ExportedEmbeddedPointerExportedMethod method | ||
func (*ExportedEmbeddedPointerAfterInterface) ExportedEmbeddedPointerExportedMethod() string { | ||
return "ExportedEmbeddedPointerExportedMethodResponse" | ||
} | ||
|
||
// EmbeddedCase2 model | ||
type EmbeddedCase2 struct { | ||
*unexportedEmbeddedPointer | ||
} | ||
|
||
type unexportedEmbeddedPointer struct{} | ||
|
||
// UnexportedEmbeddedPointerExportedMethod method | ||
func (*unexportedEmbeddedPointer) UnexportedEmbeddedPointerExportedMethod() string { | ||
return "UnexportedEmbeddedPointerExportedMethodResponse" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
extend type Query { | ||
embeddedCase1: EmbeddedCase1 | ||
embeddedCase2: EmbeddedCase2 | ||
} | ||
|
||
type EmbeddedCase1 @goModel(model:"testserver.EmbeddedCase1") { | ||
exportedEmbeddedPointerExportedMethod: String! | ||
} | ||
|
||
type EmbeddedCase2 @goModel(model:"testserver.EmbeddedCase2") { | ||
unexportedEmbeddedPointerExportedMethod: String! | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package testserver | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/99designs/gqlgen/client" | ||
"github.com/99designs/gqlgen/handler" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestEmbedded(t *testing.T) { | ||
resolver := &Stub{} | ||
resolver.QueryResolver.EmbeddedCase1 = func(ctx context.Context) (*EmbeddedCase1, error) { | ||
return &EmbeddedCase1{}, nil | ||
} | ||
resolver.QueryResolver.EmbeddedCase2 = func(ctx context.Context) (*EmbeddedCase2, error) { | ||
return &EmbeddedCase2{&unexportedEmbeddedPointer{}}, nil | ||
} | ||
|
||
c := client.New(handler.GraphQL( | ||
NewExecutableSchema(Config{Resolvers: resolver}), | ||
)) | ||
|
||
t.Run("embedded case 1", func(t *testing.T) { | ||
var resp struct { | ||
EmbeddedCase1 struct { | ||
ExportedEmbeddedPointerExportedMethod string | ||
} | ||
} | ||
err := c.Post(`query { embeddedCase1 { exportedEmbeddedPointerExportedMethod } }`, &resp) | ||
require.NoError(t, err) | ||
require.Equal(t, resp.EmbeddedCase1.ExportedEmbeddedPointerExportedMethod, "ExportedEmbeddedPointerExportedMethodResponse") | ||
}) | ||
|
||
t.Run("embedded case 2", func(t *testing.T) { | ||
var resp struct { | ||
EmbeddedCase2 struct { | ||
UnexportedEmbeddedPointerExportedMethod string | ||
} | ||
} | ||
err := c.Post(`query { embeddedCase2 { unexportedEmbeddedPointerExportedMethod } }`, &resp) | ||
require.NoError(t, err) | ||
require.Equal(t, resp.EmbeddedCase2.UnexportedEmbeddedPointerExportedMethod, "UnexportedEmbeddedPointerExportedMethodResponse") | ||
}) | ||
} |
Oops, something went wrong.