github.com/99designs/gqlgen@v0.17.45/codegen/testserver/singlefile/scalar_default_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 TestDefaultScalarImplementation(t *testing.T) { 14 resolvers := &Stub{} 15 16 c := client.New(handler.NewDefaultServer(NewExecutableSchema(Config{Resolvers: resolvers}))) 17 18 resolvers.QueryResolver.DefaultScalar = func(ctx context.Context, arg string) (i string, e error) { 19 return arg, nil 20 } 21 22 t.Run("with arg value", func(t *testing.T) { 23 var resp struct{ DefaultScalar string } 24 c.MustPost(`query { defaultScalar(arg: "fff") }`, &resp) 25 require.Equal(t, "fff", resp.DefaultScalar) 26 }) 27 28 t.Run("with default value", func(t *testing.T) { 29 var resp struct{ DefaultScalar string } 30 c.MustPost(`query { defaultScalar }`, &resp) 31 require.Equal(t, "default", resp.DefaultScalar) 32 }) 33 }