Files
dbx/ksuid_gql.go
T
end a303e025b2 feat: add StringKSUID and BinaryKSUID types
Replace the UUID wrapper with storage-specific KSUID types that share
GraphQL string transit but use distinct SQL Scan/Value encodings.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-29 17:47:41 -07:00

38 lines
806 B
Go

package dbx
import (
"encoding/json"
"fmt"
"io"
"github.com/segmentio/ksuid"
)
type ksuidGQLTransport struct {
KSUIDStr string `json:"ksuid_str"`
}
func unmarshalKSUIDFromGQL(value any, unmarshal func([]byte) error) error {
str, ok := value.(string)
if !ok {
return fmt.Errorf("GraphQL failed to unmarshal KSUID value: %v", value)
}
return unmarshal([]byte(str))
}
func marshalKSUIDToGQL(w io.Writer, id ksuid.KSUID) {
transport := ksuidGQLTransport{KSUIDStr: id.String()}
data, err := json.Marshal(transport)
if err != nil {
panic(fmt.Errorf("GraphQL failed to JSON-marshal KSUID value: %s", err))
}
if _, err := w.Write(data); err != nil {
panic(fmt.Errorf("GraphQL failed to write KSUID value: %s", string(data)))
}
}
const (
ksuidBinaryLength = 20
ksuidStringLength = 27
)