github.com/operandinc/gqlgen@v0.16.1/codegen/testserver/followschema/ptr_to_slice_test.go (about)

     1  package followschema
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	"github.com/operandinc/gqlgen/client"
     8  	"github.com/operandinc/gqlgen/graphql/handler"
     9  	"github.com/stretchr/testify/require"
    10  )
    11  
    12  func TestPtrToSlice(t *testing.T) {
    13  	resolvers := &Stub{}
    14  
    15  	c := client.New(handler.NewDefaultServer(NewExecutableSchema(Config{Resolvers: resolvers})))
    16  
    17  	resolvers.QueryResolver.PtrToSliceContainer = func(ctx context.Context) (wrappedStruct *PtrToSliceContainer, e error) {
    18  		ptrToSliceContainer := PtrToSliceContainer{
    19  			PtrToSlice: &[]string{"hello"},
    20  		}
    21  		return &ptrToSliceContainer, nil
    22  	}
    23  
    24  	t.Run("pointer to slice", func(t *testing.T) {
    25  		var resp struct {
    26  			PtrToSliceContainer struct {
    27  				PtrToSlice []string
    28  			}
    29  		}
    30  
    31  		err := c.Post(`query { ptrToSliceContainer {  ptrToSlice }}`, &resp)
    32  		require.NoError(t, err)
    33  
    34  		require.Equal(t, []string{"hello"}, resp.PtrToSliceContainer.PtrToSlice)
    35  	})
    36  }