Files
dbx/ksuid_gql.go
end cc44931ea9 feat(ksuid): add Equal and IsZero for ApplyInterfacePtr
StringKSUID and BinaryKSUID now implement ApplyInterface with nil-nil
equality semantics, enabling ApplyInterfacePtr in patch logic. Adds nil
sentinel vars and tests.

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

38 lines
780 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
)
func equalKSUID(lh, rh ksuid.KSUID) bool {
if lh.IsNil() && rh.IsNil() {
return true
}
return lh.String() == rh.String()
}