Specialized validation for books, classifications, versions, and other domain-specific formats. These scalars provide validation for specialized data types used in specific industries and use cases.
Validates International Standard Book Number format.
/**
* GraphQL scalar for ISBN validation
* Accepts both ISBN-10 and ISBN-13 formats with check digit validation
*/
const GraphQLISBN: GraphQLScalarType;Example Values:
"978-0-13-110362-7" (ISBN-13 with hyphens)"9780131103627" (ISBN-13 without hyphens)"0-13-110362-8" (ISBN-10 with hyphens)"0131103628" (ISBN-10 without hyphens)Validates Dewey Decimal Classification numbers.
/**
* GraphQL scalar for Dewey Decimal Classification validation
* Accepts DDC numbers in standard format (000-999 with optional decimal extensions)
*/
const GraphQLDeweyDecimal: GraphQLScalarType;Example Values:
"004.678" (Computer programming)"796.332" (American football)"641.5" (Cooking)"150" (Psychology)"821.914" (Modern English poetry)Validates Library of Congress Classification subclass codes.
/**
* GraphQL scalar for Library of Congress Classification subclass validation
* Accepts LCC subclass format (letter combinations followed by numbers)
*/
const GraphQLLCCSubclass: GraphQLScalarType;Example Values:
"QA76.73" (Computer programming languages)"PR6001" (English literature)"TX714" (Cooking)"BF121" (Psychology)"Z695.1" (Library science)Validates International Patent Classification codes.
/**
* GraphQL scalar for International Patent Classification validation
* Accepts IPC format for patent classification
*/
const GraphQLIPCPatent: GraphQLScalarType;Example Values:
"H04L29/06" (Network protocols)"G06F21/62" (Computer security)"A61K31/4427" (Pharmaceutical compounds)"B60W30/14" (Vehicle control systems)Validates Semantic Version format.
/**
* GraphQL scalar for Semantic Version validation
* Accepts semver format: MAJOR.MINOR.PATCH with optional pre-release and build metadata
*/
const GraphQLSemVer: GraphQLScalarType;Example Values:
"1.0.0" (Basic version)"2.1.3" (Patch version)"1.0.0-alpha" (Pre-release)"1.0.0-alpha.1" (Pre-release with number)"1.0.0+20130313144700" (With build metadata)"1.0.0-beta.2+exp.sha.5114f85" (Complex version)Validates Swedish Social Security Number format.
/**
* GraphQL scalar for Swedish Social Security Number validation
* Accepts Swedish personnummer format with check digit validation
*/
const GraphQLSESSN: GraphQLScalarType;Example Values:
"121212-1212" (Standard format)"19121212-1212" (With century)"121212+1212" (Born before 1900, using + separator)Represents void/null type for operations that return no meaningful value.
/**
* GraphQL scalar for void/null type
* Accepts null or undefined values only
*/
const GraphQLVoid: GraphQLScalarType;Example Values:
nullundefined (serialized as null)import {
GraphQLISBN,
GraphQLSemVer,
GraphQLDeweyDecimal,
GraphQLVoid
} from "graphql-scalars";
// In a GraphQL schema
const BookType = new GraphQLObjectType({
name: "Book",
fields: {
isbn: { type: GraphQLISBN },
deweyDecimal: { type: GraphQLDeweyDecimal },
version: { type: GraphQLSemVer },
},
});
const SoftwareType = new GraphQLObjectType({
name: "Software",
fields: {
version: { type: GraphQLSemVer },
},
});
// Using with type definitions
const typeDefs = `
scalar ISBN
scalar SemVer
scalar DeweyDecimal
scalar LCCSubclass
scalar IPCPatent
scalar SESSN
scalar Void
type Book {
id: ID!
title: String!
isbn: ISBN
deweyDecimal: DeweyDecimal
lccSubclass: LCCSubclass
}
type Software {
name: String!
version: SemVer!
previousVersion: SemVer
}
type Patent {
id: ID!
title: String!
ipcClassification: IPCPatent
}
type Mutation {
deleteItem(id: ID!): Void
}
`;GraphQL Operations:
query GetBook($isbn: ISBN!) {
bookByISBN(isbn: $isbn) {
id
title
isbn
deweyDecimal
lccSubclass
}
}
query GetSoftwareVersions($name: String!) {
software(name: $name) {
name
version
releases {
version
releaseDate
}
}
}
mutation DeleteBook($id: ID!): Void {
deleteBook(id: $id)
}Variables:
{
"isbn": "978-0-13-110362-7",
"name": "my-awesome-library",
"id": "book-123"
}Each specialized scalar performs domain-specific validation:
Validation Examples:
// Valid specialized data
const validData = {
isbn: "978-0-13-110362-7", // Valid ISBN-13
semver: "2.1.3-alpha.1", // Valid semantic version
dewey: "004.678", // Valid DDC number
lcc: "QA76.73", // Valid LCC subclass
ipc: "H04L29/06", // Valid IPC code
sessn: "121212-1212", // Valid Swedish SSN
voidValue: null // Valid void value
};
// Invalid specialized data
const invalidData = {
isbn: "978-0-13-110362-8", // Invalid check digit
semver: "2.1", // Missing patch version
dewey: "1000.1", // Invalid range (> 999)
lcc: "INVALID123", // Invalid format
ipc: "INVALID/CODE", // Invalid IPC format
sessn: "999999-9999", // Invalid Swedish SSN
voidValue: "not-null" // Invalid for void type
};Library Systems use these scalars for:
Software Development uses:
Patent Systems use:
Government/Identity Systems use:
The SemVer scalar supports full semantic versioning specification:
Version Format: MAJOR.MINOR.PATCH[-PRERELEASE][+BUILD]
Precedence Rules:
1.0.0 < 2.0.0 < 2.1.0 < 2.1.11.0.0-alpha < 1.0.0-alpha.1 < 1.0.0-beta < 1.0.0// String constants for schema building
const ISBN: string; // "scalar ISBN"
const SemVer: string; // "scalar SemVer"
const DeweyDecimal: string; // "scalar DeweyDecimal"
const LCCSubclass: string; // "scalar LCCSubclass"
const IPCPatent: string; // "scalar IPCPatent"
const SESSN: string; // "scalar SESSN"
const Void: string; // "scalar Void"// Mock data generators for testing
const ISBNMock: () => string;
const SemVerMock: () => string;
const DeweyDecimalMock: () => string;
const LCCSubclassMock: () => string;
const IPCPatentMock: () => string;
const SESSNMock: () => string;
const VoidMock: () => null;These specialized scalars are particularly useful in: