-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
- Loading branch information
There are no files selected for viewing
Large diffs are not rendered by default.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
extend type Query { | ||
slices: Slices | ||
} | ||
|
||
type Slices { | ||
test1: [String] | ||
test2: [String!] | ||
test3: [String]! | ||
test4: [String!]! | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package testserver | ||
|
||
import ( | ||
"context" | ||
"net/http/httptest" | ||
"testing" | ||
|
||
"github.com/99designs/gqlgen/client" | ||
"github.com/99designs/gqlgen/handler" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestSlices(t *testing.T) { | ||
resolvers := &Stub{} | ||
|
||
srv := httptest.NewServer(handler.GraphQL(NewExecutableSchema(Config{Resolvers: resolvers}))) | ||
c := client.New(srv.URL) | ||
|
||
t.Run("nulls vs empty slices", func(t *testing.T) { | ||
resolvers.QueryResolver.Slices = func(ctx context.Context) (slices *Slices, e error) { | ||
return &Slices{}, nil | ||
} | ||
|
||
var resp struct { | ||
Slices Slices | ||
} | ||
c.MustPost(`query { slices { test1, test2, test3, test4 }}`, &resp) | ||
require.Nil(t, resp.Slices.Test1) | ||
require.Nil(t, resp.Slices.Test2) | ||
require.NotNil(t, resp.Slices.Test3) | ||
require.NotNil(t, resp.Slices.Test4) | ||
}) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.