Files
dbx/ksuid_gql.go
T
end 0f8e79a890 refactor: use GraphQL string scalar for KSUID transit
Marshal and unmarshal both use the base62 KSUID string, replacing the
legacy JSON object wrapper and aligning gqlgen scalar behavior.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-29 18:03:39 -07:00

31 lines
651 B
Go

package dbx
import (
"fmt"
"io"
"strconv"
"github.com/segmentio/ksuid"
)
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))
}
// marshalKSUIDToGQL writes a JSON-encoded string scalar for gqlgen.
func marshalKSUIDToGQL(w io.Writer, id ksuid.KSUID) {
quoted := strconv.Quote(id.String())
if _, err := io.WriteString(w, quoted); err != nil {
panic(fmt.Errorf("GraphQL failed to write KSUID value: %w", err))
}
}
const (
ksuidBinaryLength = 20
ksuidStringLength = 27
)