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

     1  package followschema
     2  
     3  import (
     4  	"fmt"
     5  	"io"
     6  
     7  	"github.com/luciferinlove/gqlgen/graphql"
     8  )
     9  
    10  func MarshalBytes(b []byte) graphql.Marshaler {
    11  	return graphql.WriterFunc(func(w io.Writer) {
    12  		_, _ = fmt.Fprintf(w, "%q", string(b))
    13  	})
    14  }
    15  
    16  func UnmarshalBytes(v interface{}) ([]byte, error) {
    17  	switch v := v.(type) {
    18  	case string:
    19  		return []byte(v), nil
    20  	case *string:
    21  		return []byte(*v), nil
    22  	case []byte:
    23  		return v, nil
    24  	default:
    25  		return nil, fmt.Errorf("%T is not []byte", v)
    26  	}
    27  }