github.com/99designs/gqlgen@v0.17.45/codegen/testserver/singlefile/ptr_to_any_test.go (about) 1 package singlefile 2 3 import ( 4 "context" 5 "testing" 6 7 "github.com/stretchr/testify/require" 8 9 "github.com/99designs/gqlgen/client" 10 "github.com/99designs/gqlgen/graphql/handler" 11 ) 12 13 func TestPtrToAny(t *testing.T) { 14 resolvers := &Stub{} 15 16 c := client.New(handler.NewDefaultServer(NewExecutableSchema(Config{Resolvers: resolvers}))) 17 18 var a any = `{"some":"thing"}` 19 resolvers.QueryResolver.PtrToAnyContainer = func(ctx context.Context) (wrappedStruct *PtrToAnyContainer, e error) { 20 ptrToAnyContainer := PtrToAnyContainer{ 21 PtrToAny: &a, 22 } 23 return &ptrToAnyContainer, nil 24 } 25 26 t.Run("binding to pointer to any", func(t *testing.T) { 27 var resp struct { 28 PtrToAnyContainer struct { 29 Binding *any 30 } 31 } 32 33 err := c.Post(`query { ptrToAnyContainer { binding }}`, &resp) 34 require.NoError(t, err) 35 36 require.Equal(t, &a, resp.PtrToAnyContainer.Binding) 37 }) 38 }