Skip to content

Commit

Permalink
adding tests for pointer to slice
Browse files Browse the repository at this point in the history
  • Loading branch information
ananyasaxena committed Oct 17, 2020
1 parent 15a6896 commit e37359b
Show file tree
Hide file tree
Showing 6 changed files with 212 additions and 0 deletions.
153 changes: 153 additions & 0 deletions codegen/testserver/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions codegen/testserver/ptr_to_slice.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package testserver

type PtrToSliceContainer struct {
PtrToSlice *[]string
}
7 changes: 7 additions & 0 deletions codegen/testserver/ptr_to_slice.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
type PtrToSliceContainer {
ptrToSlice: [String!]
}

extend type Query {
ptrToSliceContainer: PtrToSliceContainer!
}
39 changes: 39 additions & 0 deletions codegen/testserver/ptr_to_slice_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
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)

})
}
4 changes: 4 additions & 0 deletions codegen/testserver/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,10 @@ func (r *queryResolver) PrimitiveStringObject(ctx context.Context) ([]PrimitiveS
panic("not implemented")
}

func (r *queryResolver) PtrToSliceContainer(ctx context.Context) (*PtrToSliceContainer, error) {
panic("not implemented")
}

func (r *queryResolver) DefaultScalar(ctx context.Context, arg string) (string, error) {
panic("not implemented")
}
Expand Down
4 changes: 4 additions & 0 deletions codegen/testserver/stub.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e37359b

Please sign in to comment.