代码拉取完成,页面将自动刷新
package graphql
import (
"context"
"testing"
"github.com/stretchr/testify/require"
"github.com/vektah/gqlparser/v2/ast"
)
func TestGetOperationContext(t *testing.T) {
rc := &OperationContext{}
t.Run("with operation context", func(t *testing.T) {
ctx := WithOperationContext(context.Background(), rc)
require.True(t, HasOperationContext(ctx))
require.Equal(t, rc, GetOperationContext(ctx))
})
t.Run("without operation context", func(t *testing.T) {
ctx := context.Background()
require.False(t, HasOperationContext(ctx))
require.Panics(t, func() {
GetOperationContext(ctx)
})
})
}
func TestCollectAllFields(t *testing.T) {
t.Run("collect fields", func(t *testing.T) {
ctx := testContext(ast.SelectionSet{
&ast.Field{
Name: "field",
},
})
s := CollectAllFields(ctx)
require.Equal(t, []string{"field"}, s)
})
t.Run("unique field names", func(t *testing.T) {
ctx := testContext(ast.SelectionSet{
&ast.Field{
Name: "field",
},
&ast.Field{
Name: "field",
Alias: "field alias",
},
})
s := CollectAllFields(ctx)
require.Equal(t, []string{"field"}, s)
})
t.Run("collect fragments", func(t *testing.T) {
ctx := testContext(ast.SelectionSet{
&ast.Field{
Name: "fieldA",
},
&ast.InlineFragment{
TypeCondition: "ExampleTypeA",
SelectionSet: ast.SelectionSet{
&ast.Field{
Name: "fieldA",
},
},
},
&ast.InlineFragment{
TypeCondition: "ExampleTypeB",
SelectionSet: ast.SelectionSet{
&ast.Field{
Name: "fieldB",
},
},
},
})
s := CollectAllFields(ctx)
require.Equal(t, []string{"fieldA", "fieldB"}, s)
})
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。