JSPM

graphql-scalar-unix-time-sec

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 216
  • Score
    100M100P100Q89030F
  • License Apache-2.0

A GraphQL scalar for representing unix time seconds

Package Exports

  • graphql-scalar-unix-time-sec

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (graphql-scalar-unix-time-sec) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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