graphql-type-decimal

1.0.0 • Public • Published

graphql-type-decimal

Decimal scalar type for GraphQL.js primarily for currencies.

Ex: 21.01

Usage

This package exports a Decimal scalar GraphQL.js type:

import GraphQLDecimal from 'graphql-type-decimal';

SDL with GraphQL-tools

When using the SDL with GraphQL-tools, define GraphQLDecimal as the resolver for the appropriate scalar type in your schema:

import { makeExecutableSchema } from 'graphql-tools';
import GraphQLDecimal from 'graphql-type-decimal';
 
const typeDefs = `
scalar Decimal
 
type MyType {
  myField: Decimal
}
 
# ...
`;
 
const resolvers = {
  Decimal: GraphQLDecimal,
};
 
export default makeExecutableSchema({ typeDefs, resolvers });

Dependency

This library uses bignumber.js

Related

This repository is inspired by graphql-type-datetime

Readme

Keywords

Package Sidebar

Install

npm i graphql-type-decimal

Weekly Downloads

410

Version

1.0.0

License

MIT

Unpacked Size

4.72 kB

Total Files

4

Last publish

Collaborators

  • shotwhat