Socket
Socket
Sign inDemoInstall

graphql-scalar-unix-time-sec

Package Overview
Dependencies
2
Maintainers
2
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    graphql-scalar-unix-time-sec

A GraphQL scalar for representing unix time seconds


Version published
Maintainers
2
Install size
1.85 MB
Created

Readme

Source

graphql-scalar-unix-time-sec

A GraphQL scalar for representing unix time seconds

Install

npm i --save graphql-scalar-unix-time-sec

Usage

  1. Import
import unixTimeSec from 'graphql-scalar-unix-time-sec';
  1. Use the scalar in the gql schema file
const typeDefs = gql`
    type User {
        createdAt: ${unixTimeSec.type.name}
        input: ${unixTimeSec.type.name}
    }

    type Query {
        user(input: ${unixTimeSec.type.name}): User
    }
    
    ${unixTimeSec.typedef}
`;

or

type User {
    createdAt: UnixTimeSec
    input: UnixTimeSec
}

type Query {
    user(input: UnixTimeSec): User
}

scalar UnixTimeSec
  1. Add the resolver
const resolvers = {
    ...unixTimeSec.resolver,
    Query: {
        async user(_, input: any) {
            return {...returnValues.user, ...input};
        }
    }
};

Features

This scalar will:

  • Accept inputs in either string or number format
  • Validate that the input type has 10 digits (aka is between the years ~1974 to ~2463)
  • Will coerce milliseconds to seconds if being sent from the server to client

Keywords

FAQs

Last updated on 23 Dec 2020

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc