github.com/99designs/gqlgen@v0.17.45/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 ctx := context.Background() 20 21 rqCtx := &OperationContext{} 22 ctx = WithOperationContext(ctx, rqCtx) 23 24 root := &FieldContext{ 25 Field: CollectedField{ 26 Selections: sel, 27 }, 28 } 29 ctx = WithFieldContext(ctx, root) 30 31 return ctx 32 }