github.com/spread-ai/gqlgen@v0.0.0-20221124102857-a6c8ef538a1d/graphql/context_root_field.go (about)

     1  package graphql
     2  
     3  import (
     4  	"context"
     5  )
     6  
     7  const rootResolverCtx key = "root_resolver_context"
     8  
     9  type RootFieldContext struct {
    10  	// The name of the type this field belongs to
    11  	Object string
    12  	// The raw field
    13  	Field CollectedField
    14  }
    15  
    16  func GetRootFieldContext(ctx context.Context) *RootFieldContext {
    17  	if val, ok := ctx.Value(rootResolverCtx).(*RootFieldContext); ok {
    18  		return val
    19  	}
    20  	return nil
    21  }
    22  
    23  func WithRootFieldContext(ctx context.Context, rc *RootFieldContext) context.Context {
    24  	return context.WithValue(ctx, rootResolverCtx, rc)
    25  }