Package Exports
- graphql-scalar
- graphql-scalar/dist/browser/index.js
- graphql-scalar/dist/node/index.js
- graphql-scalar/lib/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (graphql-scalar) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
graphql-scalar
Configurable custom GraphQL Scalars (string, number, date, etc) with sanitization / validation / transformation in TypeScript.
TypeScript version (with breaking changes) of the following repos:
joonhocho/graphql-input-number
joonhocho/graphql-input-string
Get Started
npm install graphql-scalar
or
yarn add graphql-scalar
How to Use
import { createStringScalar, createIntScalar, createFloatScalar } from 'graphql-scalar';
const stringScalar = createStringScalar({
name: string;
description?: string;
capitalize?: 'characters' | 'words' | 'sentences' | 'first';
collapseWhitespace?: boolean;
lowercase?: boolean;
maxLength?: number;
minLength?: number;
nonEmpty?: boolean;
pattern?: RegExp | string;
singleline?: string;
trim?: boolean;
trimLeft?: boolean;
trimRight?: boolean;
truncate?: number;
uppercase?: boolean;
coerce?: ScalarCoerceFunction<TValue>;
errorHandler?: ScalarParseErrorHandler<TInternal, TConfig, TErrorCode>;
parse?: ScalarParseFunction<TValue, TInternal>;
sanitize?: ScalarSanitizeFunction<TValue>;
serialize?: ScalarSerializeFunction<TInternal, TExternal>;
validate?: ScalarValidateFunction<TValue>;
})
const intScalar = createIntScalar({
name: string;
description?: string;
maximum?: number;
minimum?: number;
coerce?: ScalarCoerceFunction<TValue>;
errorHandler?: ScalarParseErrorHandler<TInternal, TConfig, TErrorCode>;
parse?: ScalarParseFunction<TValue, TInternal>;
sanitize?: ScalarSanitizeFunction<TValue>;
serialize?: ScalarSerializeFunction<TInternal, TExternal>;
validate?: ScalarValidateFunction<TValue>;
})