All Projects → joonhocho → graphql-scalar

joonhocho / graphql-scalar

Licence: MIT license
Configurable custom GraphQL Scalars (string, number, date, etc) with sanitization / validation / transformation in TypeScript.

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

graphql-scalar

Configurable custom GraphQL Scalars (string, number, date, etc) with sanitization / validation / transformation in TypeScript.

npm version Build Status Coverage Status Dependency Status npm type definitions GitHub

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>;
})

License

MIT License

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].