Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

graphql-scalars

Package Overview
Dependencies
Maintainers
5
Versions
1609
Alerts
File Explorer

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.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
5
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 28 Nov 2024

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc