github.com/operandinc/gqlgen@v0.16.1/codegen/testserver/followschema/modelmethod_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 TestModelMethods(t *testing.T) { 13 resolver := &Stub{} 14 resolver.QueryResolver.ModelMethods = func(ctx context.Context) (methods *ModelMethods, e error) { 15 return &ModelMethods{}, nil 16 } 17 resolver.ModelMethodsResolver.ResolverField = func(ctx context.Context, obj *ModelMethods) (b bool, e error) { 18 return true, nil 19 } 20 21 c := client.New(handler.NewDefaultServer( 22 NewExecutableSchema(Config{Resolvers: resolver}), 23 )) 24 t.Run("without context", func(t *testing.T) { 25 var resp struct { 26 ModelMethods struct { 27 NoContext bool 28 } 29 } 30 err := c.Post(`query { modelMethods{ noContext } }`, &resp) 31 require.NoError(t, err) 32 require.True(t, resp.ModelMethods.NoContext) 33 }) 34 t.Run("with context", func(t *testing.T) { 35 var resp struct { 36 ModelMethods struct { 37 WithContext bool 38 } 39 } 40 err := c.Post(`query { modelMethods{ withContext } }`, &resp) 41 require.NoError(t, err) 42 require.True(t, resp.ModelMethods.WithContext) 43 }) 44 }