Skip to content

idScalar

idScalar<Brand>(codec, config): GraphQLScalarType<Id<Brand>, string>

Defined in: src/adapters/graphql.ts:35

Builds a GraphQLScalarType for the given codec and brand.

  • serialize — validates strictly via codec.is(); throws GraphQLError on a non-canonical value and returns the value unchanged (no normalization) on success.
  • parseValue — validates variables via codec.safeParse; throws GraphQLError on failure. Accepts mixed-case and Crockford visual aliases; always returns the canonical form.
  • parseLiteral — validates inline Kind.STRING literals the same way as parseValue; throws GraphQLError for any other AST kind or on a failed safeParse.

graphql must be installed as a peer dependency.

Brand extends string

GraphQLCodec<Brand>

string

string

GraphQLScalarType<Id<Brand>, string>

import { idScalar } from "@smonn/ids/graphql";
import { createTimestampId } from "@smonn/ids";
const usr = createTimestampId("usr");
const UserIdScalar = idScalar(usr, { name: "UserId", description: "A branded user ID." });