...

Source file src/github.com/99designs/gqlgen/codegen/testserver/singlefile/bytes.go

Documentation: github.com/99designs/gqlgen/codegen/testserver/singlefile

     1  package singlefile
     2  
     3  import (
     4  	"fmt"
     5  	"io"
     6  
     7  	"github.com/99designs/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  }
    28  

View as plain text