1 回答
TA贡献1770条经验 获得超3个赞
测试时,使用以下参数创建客户端:
// WithContext defines a client.Option to pass context.
func WithContext(ctx context.Context) client.Option {
return client.Option(func(r *client.Request) {
r.HTTP = r.HTTP.WithContext(ctx)
})
}
func TestGraphql(t *testing.T) {
opts := []enttest.Option{
enttest.WithOptions(ent.Log(t.Log)),
enttest.WithMigrateOptions(migrate.WithGlobalUniqueID(true)),
}
entClient := enttest.Open(t, "sqlite3", "file:ent?mode=memory&cache=shared&_fk=1", opts...)
handler := handler.NewDefaultServer(gql.NewSchema(entClient, &trustly.Client{}))
handler.Use(entgql.Transactioner{TxOpener: entClient})
defer entClient.Close()
err := c.Post(`query{}....`, &output, WithContext(privacy.DecisionContext(context.Background(), privacy.Allow)))
}
- 1 回答
- 0 关注
- 84 浏览
添加回答
举报