-
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.
Special handling for pointers to slices (#1363)
- Loading branch information
1 parent
c920bde
commit 3f68ea2
Showing
10 changed files
with
228 additions
and
5 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,5 @@ | ||
package testserver | ||
|
||
type PtrToSliceContainer struct { | ||
PtrToSlice *[]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,7 @@ | ||
type PtrToSliceContainer { | ||
ptrToSlice: [String!] | ||
} | ||
|
||
extend type Query { | ||
ptrToSliceContainer: PtrToSliceContainer! | ||
} |
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,37 @@ | ||
package testserver | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/99designs/gqlgen/client" | ||
"github.com/99designs/gqlgen/graphql/handler" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestPtrToSlice(t *testing.T) { | ||
resolvers := &Stub{} | ||
|
||
c := client.New(handler.NewDefaultServer(NewExecutableSchema(Config{Resolvers: resolvers}))) | ||
|
||
resolvers.QueryResolver.PtrToSliceContainer = func(ctx context.Context) (wrappedStruct *PtrToSliceContainer, e error) { | ||
ptrToSliceContainer := PtrToSliceContainer{ | ||
PtrToSlice: &[]string{"hello"}, | ||
} | ||
return &ptrToSliceContainer, nil | ||
} | ||
|
||
t.Run("pointer to slice", func(t *testing.T) { | ||
var resp struct { | ||
PtrToSliceContainer struct { | ||
PtrToSlice []string | ||
} | ||
} | ||
|
||
err := c.Post(`query { ptrToSliceContainer { ptrToSlice }}`, &resp) | ||
require.NoError(t, err) | ||
|
||
require.Equal(t, []string{"hello"}, resp.PtrToSliceContainer.PtrToSlice) | ||
|
||
}) | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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