...

Source file src/github.com/99designs/gqlgen/graphql/uuid.go

Documentation: github.com/99designs/gqlgen/graphql

     1  package graphql
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/google/uuid"
     7  )
     8  
     9  func MarshalUUID(id uuid.UUID) Marshaler {
    10  	if id == uuid.Nil {
    11  		return Null
    12  	}
    13  	return MarshalString(id.String())
    14  }
    15  
    16  func UnmarshalUUID(v any) (uuid.UUID, error) {
    17  	switch v := v.(type) {
    18  	case string:
    19  		return uuid.Parse(v)
    20  	case []byte:
    21  		return uuid.ParseBytes(v)
    22  	default:
    23  		return uuid.Nil, fmt.Errorf("%T is not a uuid", v)
    24  	}
    25  }
    26  

View as plain text