🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more

graphql-scalars

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphql-scalars

A collection of scalar types not included in base GraphQL.

1.24.2
latest
100

Supply Chain Security

100

Vulnerability

87

Quality

90

Maintenance

100

License

Version published
Weekly downloads
847K
-17.02%
Maintainers
5
Weekly downloads
 
Created

What is graphql-scalars?

The graphql-scalars npm package provides a collection of custom GraphQL scalar types for common use cases not covered by the default GraphQL specification. These scalars help in validating and parsing data types such as DateTime, Email, URL, and more, making it easier to handle various data formats in a GraphQL API.

What are graphql-scalars's main functionalities?

DateTime Scalar

The DateTime scalar type is used to handle ISO 8601 date and time strings. This is useful for ensuring that date and time values are properly formatted and validated.

const { DateTimeResolver } = require('graphql-scalars');

const typeDefs = gql`
  scalar DateTime

  type Event {
    id: ID!
    name: String!
    date: DateTime!
  }
`;

const resolvers = {
  DateTime: DateTimeResolver,
};

Email Scalar

The Email scalar type is used to validate email addresses. This ensures that any email address provided in the GraphQL API is in a valid format.

const { EmailAddressResolver } = require('graphql-scalars');

const typeDefs = gql`
  scalar EmailAddress

  type User {
    id: ID!
    email: EmailAddress!
  }
`;

const resolvers = {
  EmailAddress: EmailAddressResolver,
};

URL Scalar

The URL scalar type is used to validate URLs. This ensures that any URL provided in the GraphQL API is in a valid format.

const { URLResolver } = require('graphql-scalars');

const typeDefs = gql`
  scalar URL

  type Website {
    id: ID!
    url: URL!
  }
`;

const resolvers = {
  URL: URLResolver,
};

JSON Scalar

The JSON scalar type is used to handle arbitrary JSON objects. This is useful for fields that need to store complex data structures.

const { JSONResolver } = require('graphql-scalars');

const typeDefs = gql`
  scalar JSON

  type Config {
    id: ID!
    settings: JSON!
  }
`;

const resolvers = {
  JSON: JSONResolver,
};

Other packages similar to graphql-scalars

FAQs

Package last updated on 19 Mar 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts