github.com/luciferinlove/gqlgen@v0.17.16-bzc.1/codegen/testserver/followschema/scalar_context.go (about)

     1  package followschema
     2  
     3  import (
     4  	"context"
     5  	"io"
     6  	"strconv"
     7  
     8  	"github.com/luciferinlove/gqlgen/graphql"
     9  )
    10  
    11  type StringFromContextInterface struct {
    12  	OperationName string
    13  }
    14  
    15  var (
    16  	_ graphql.ContextMarshaler   = StringFromContextInterface{}
    17  	_ graphql.ContextUnmarshaler = (*StringFromContextInterface)(nil)
    18  )
    19  
    20  func (StringFromContextInterface) MarshalGQLContext(ctx context.Context, w io.Writer) error {
    21  	io.WriteString(w, strconv.Quote(graphql.GetFieldContext(ctx).Field.Name))
    22  	return nil
    23  }
    24  
    25  func (i *StringFromContextInterface) UnmarshalGQLContext(ctx context.Context, v interface{}) error {
    26  	i.OperationName = graphql.GetFieldContext(ctx).Field.Name
    27  	return nil
    28  }
    29  
    30  func MarshalStringFromContextFunction(v string) graphql.ContextMarshaler {
    31  	return graphql.ContextWriterFunc(func(ctx context.Context, w io.Writer) error {
    32  		io.WriteString(w, strconv.Quote(graphql.GetFieldContext(ctx).Field.Name))
    33  		return nil
    34  	})
    35  }
    36  
    37  func UnmarshalStringFromContextFunction(ctx context.Context, v interface{}) (string, error) {
    38  	return graphql.GetFieldContext(ctx).Field.Name, nil
    39  }