https://github.com/joonhocho/graphql-scalar
Configurable custom GraphQL Scalars (string, number, date, etc) with sanitization / validation / transformation in TypeScript.
https://github.com/joonhocho/graphql-scalar
Last synced: 5 months ago
JSON representation
Configurable custom GraphQL Scalars (string, number, date, etc) with sanitization / validation / transformation in TypeScript.
- Host: GitHub
- URL: https://github.com/joonhocho/graphql-scalar
- Owner: joonhocho
- License: mit
- Created: 2019-06-28T04:20:15.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-07-11T01:01:53.000Z (almost 2 years ago)
- Last Synced: 2024-11-04T21:37:15.070Z (6 months ago)
- Language: TypeScript
- Homepage:
- Size: 1.01 MB
- Stars: 23
- Watchers: 3
- Forks: 2
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-ccamel - joonhocho/graphql-scalar - Configurable custom GraphQL Scalars (string, number, date, etc) with sanitization / validation / transformation in TypeScript. (TypeScript)
README
# graphql-scalar
Configurable custom GraphQL Scalars (string, number, date, etc) with sanitization / validation / transformation in TypeScript.[](https://badge.fury.io/js/graphql-scalar)
[](https://travis-ci.org/joonhocho/graphql-scalar)
[](https://coveralls.io/github/joonhocho/graphql-scalar?branch=master)
[](https://david-dm.org/joonhocho/graphql-scalar)

[](https://github.com/joonhocho/graphql-scalar/blob/master/LICENSE)TypeScript version (with breaking changes) of the following repos:
[joonhocho/graphql-input-number](https://github.com/joonhocho/graphql-input-number)
[joonhocho/graphql-input-string](https://github.com/joonhocho/graphql-input-string)## Get Started
```
npm install graphql-scalar
```
or
```
yarn add graphql-scalar
```## How to Use
```typescript
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;
errorHandler?: ScalarParseErrorHandler;
parse?: ScalarParseFunction;
sanitize?: ScalarSanitizeFunction;
serialize?: ScalarSerializeFunction;
validate?: ScalarValidateFunction;
})const intScalar = createIntScalar({
name: string;
description?: string;
maximum?: number;
minimum?: number;
coerce?: ScalarCoerceFunction;
errorHandler?: ScalarParseErrorHandler;
parse?: ScalarParseFunction;
sanitize?: ScalarSanitizeFunction;
serialize?: ScalarSerializeFunction;
validate?: ScalarValidateFunction;
})
```## License
[MIT License](https://github.com/joonhocho/graphql-scalar/blob/master/LICENSE)