为了账号安全,请及时绑定邮箱和手机立即绑定

如何禁用测试的耳鼻喉隐私设置?

如何禁用测试的耳鼻喉隐私设置?

Go
神不在的星期二 2022-11-08 15:59:21
我设置了一个 graphql 应用程序,它使用 ent 作为 ORM 和 firebase。使用 ent,我添加了隐私规则来验证哪些用户可以访问某些 graphql 方法。现在我想编写测试,但由于以下错误,我无法使用某些 graphql 方法:viewer is missing: ent/privacy: deny rule有没有办法在运行时禁用隐私规则进行测试?
查看完整描述

1 回答

?
德玛西亚99

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)))


}


查看完整回答
反对 回复 2022-11-08
  • 1 回答
  • 0 关注
  • 84 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信