github.com/fortexxx/gqlgen@v0.10.3-0.20191216030626-ca5ea8b21ead/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/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  }