github.com/maeglindeveloper/gqlgen@v0.13.1-0.20210413081235-57808b12a0a0/graphql/context_field_test.go (about) 1 package graphql 2 3 import ( 4 "context" 5 "testing" 6 7 "github.com/stretchr/testify/require" 8 "github.com/vektah/gqlparser/v2/ast" 9 ) 10 11 func TestGetResolverContext(t *testing.T) { 12 require.Nil(t, GetFieldContext(context.Background())) 13 14 rc := &FieldContext{} 15 require.Equal(t, rc, GetFieldContext(WithFieldContext(context.Background(), rc))) 16 } 17 18 func testContext(sel ast.SelectionSet) context.Context { 19 20 ctx := context.Background() 21 22 rqCtx := &OperationContext{} 23 ctx = WithOperationContext(ctx, rqCtx) 24 25 root := &FieldContext{ 26 Field: CollectedField{ 27 Selections: sel, 28 }, 29 } 30 ctx = WithFieldContext(ctx, root) 31 32 return ctx 33 }