All Projects → excitement-engineer → Graphql Iso Date

excitement-engineer / Graphql Iso Date

Licence: mit
A set of RFC 3339 compliant date/time GraphQL scalar types.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Graphql Iso Date

Postgraphile
GraphQL is a new way of communicating with your server. It eliminates the problems of over- and under-fetching, incorporates strong data types, has built-in introspection, documentation and deprecation capabilities, and is implemented in many programming languages. This all leads to gloriously low-latency user experiences, better developer experiences, and much increased productivity. Because of all this, GraphQL is typically used as a replacement for (or companion to) RESTful API services.
Stars: ✭ 10,967 (+2184.79%)
Mutual labels:  graphql, graphql-js
Join Monster
A GraphQL to SQL query execution layer for query planning and batch data fetching.
Stars: ✭ 2,395 (+398.96%)
Mutual labels:  graphql, graphql-js
Hangzhou Graphql Party
杭州 GraphQLParty 往期记录(slide,照片,预告,视频等)
Stars: ✭ 142 (-70.42%)
Mutual labels:  graphql, graphql-js
Graphql Log
Add logging to your GraphQL resolvers so you know what's going on in your app.
Stars: ✭ 94 (-80.42%)
Mutual labels:  graphql, graphql-js
Graphql Core
A Python 3.6+ port of the GraphQL.js reference implementation of GraphQL.
Stars: ✭ 344 (-28.33%)
Mutual labels:  graphql, graphql-js
Cruddl
Create a GraphQL API for your database, using the GraphQL SDL to model your schema.
Stars: ✭ 98 (-79.58%)
Mutual labels:  graphql, graphql-js
Grial
A Node.js framework for creating GraphQL API servers easily and without a lot of boilerplate.
Stars: ✭ 194 (-59.58%)
Mutual labels:  graphql, graphql-js
Type Graphql
Create GraphQL schema and resolvers with TypeScript, using classes and decorators!
Stars: ✭ 6,864 (+1330%)
Mutual labels:  graphql, graphql-js
Graphql Js
A reference implementation of GraphQL for JavaScript
Stars: ✭ 18,251 (+3702.29%)
Mutual labels:  graphql, graphql-js
Graphql To Mongodb
Allows for generic run-time generation of filter types for existing graphql types and parsing client requests to mongodb find queries
Stars: ✭ 261 (-45.62%)
Mutual labels:  graphql, graphql-js
Graphql Rxjs
fork of Graphql which adds Observable support
Stars: ✭ 78 (-83.75%)
Mutual labels:  graphql, graphql-js
Graphql Tools
🔧 Build, mock, and stitch a GraphQL schema using the schema language
Stars: ✭ 4,556 (+849.17%)
Mutual labels:  graphql, graphql-js
Graphql Scalars
A library of custom GraphQL Scalars for creating precise type-safe GraphQL schemas.
Stars: ✭ 1,023 (+113.13%)
Mutual labels:  graphql, graphql-js
The Road To Graphql Chinese
📓The Road to GraphQL: Your journey to master pragmatic GraphQL in JavaScript
Stars: ✭ 104 (-78.33%)
Mutual labels:  graphql, graphql-js
Aws Mobile Appsync Sdk Js
JavaScript library files for Offline, Sync, Sigv4. includes support for React Native
Stars: ✭ 806 (+67.92%)
Mutual labels:  graphql, graphql-js
Graphql2rest
GraphQL to REST converter: automatically generate a RESTful API from your existing GraphQL API
Stars: ✭ 181 (-62.29%)
Mutual labels:  graphql, graphql-js
Graphql Cost Analysis
A Graphql query cost analyzer.
Stars: ✭ 527 (+9.79%)
Mutual labels:  graphql, graphql-js
React App
Create React App with server-side code support
Stars: ✭ 614 (+27.92%)
Mutual labels:  graphql, graphql-js
The Road To Graphql
📓The Road to GraphQL: Your journey to master pragmatic GraphQL in JavaScript
Stars: ✭ 203 (-57.71%)
Mutual labels:  graphql, graphql-js
Typegql
Create GraphQL schema with TypeScript classes.
Stars: ✭ 415 (-13.54%)
Mutual labels:  graphql, graphql-js

GraphQL ISO Date

npm version Build Status codecov

NOTICE: The scalars defined in this repository have moved to the GraphQL-scalars repository where they will be maintained.

GraphQL ISO Date is a set of RFC 3339 compliant date/time scalar types to be used with graphQL.js.

RFC 3339 "defines a date and time format for use in Internet protocols that is a profile of the ISO 8601 standard for representation of dates and times using the Gregorian calendar."

Date and Time on the Internet: Timestamps, July 2002.

A basic understanding of GraphQL and of the graphQL.js implementation is needed to provide context for this library.

This library contains the following scalars:

  • Date: A date string, such as 2007-12-03.
  • Time: A time string at UTC, such as 10:15:30Z
  • DateTime: A date-time string at UTC, such as 2007-12-03T10:15:30Z.

Getting started

Install graphql-iso-date using yarn

yarn add graphql-iso-date

Or using npm

npm install --save graphql-iso-date

GraphQL ISO Date exposes 3 different date/time scalars that can be used in combination with graphQL.js. Let's build a simple schema using the scalars included in this library and execute a query:

import {
  graphql,
  GraphQLObjectType,
  GraphQLSchema,
} from 'graphql';

import {
  GraphQLDate,
  GraphQLTime,
  GraphQLDateTime
} from 'graphql-iso-date';

const schema = new GraphQLSchema({
  query: new GraphQLObjectType({
    name: 'Query',
    fields: {
      birthdate: {
        type: GraphQLDate,
        //resolver can take a Date or date string.
        resolve: () => new Date(1991, 11, 24)
      },
      openingNYSE: {
        type: GraphQLTime,
        //resolver can take a Date or time string.
        resolve: () => new Date(Date.UTC(2017, 0, 10, 14, 30))
      },
      instant: {
        type: GraphQLDateTime,
        // resolver can take Date, date-time string or Unix timestamp (number).
        resolve: () => new Date(Date.UTC(2017, 0, 10, 21, 33, 15, 233))
      }
    }
  })
});

const query = `
  {
    birthdate
    openingNYSE
    instant
  }
`;

graphql(schema, query).then(result => {

    // Prints
    // {
    //   data: {
    //     birthdate: '1991-12-24',
    //     openingNYSE: '14:30:00.000Z',
    //     instant: '2017-01-10T21:33:15.233Z'
    //   }
    // }
    console.log(result);
});

Examples

This project includes several examples in the folder /examples explaining how to use the various scalars. You can also see some live editable examples on Launchpad:

Run the examples by downloading this project and running the following commands:

Install dependencies using yarn

yarn

Or npm

npm install

Run the examples

npm run examples

Scalars

This section provides a detailed description of each of the scalars.

A reference is made to coercion in the description below. For further clarification on the meaning of this term, please refer to the GraphQL spec.

Date

A date string, such as 2007-12-03, compliant with the full-date format outlined in section 5.6 of the RFC 3339 profile of the ISO 8601 standard for representation of dates and times using the Gregorian calendar.

This scalar is a description of the date, as used for birthdays for example. It cannot represent an instant on the time-line.

Result Coercion

Javascript Date instances are coerced to an RFC 3339 compliant date string. Invalid Date instances raise a field error.

Input Coercion

When expected as an input type, only RFC 3339 compliant date strings are accepted. All other input values raise a query error indicating an incorrect type.

Time

A time string at UTC, such as 10:15:30Z, compliant with the full-time format outlined in section 5.6 of the RFC 3339 profile of the ISO 8601 standard for representation of dates and times using the Gregorian calendar.

This scalar is a description of a time instant such as the opening bell of the New York Stock Exchange for example. It cannot represent an exact instant on the time-line.

This scalar ignores leap seconds (thereby assuming that a minute constitutes of 59 seconds), in this respect it diverges from the RFC 3339 profile.

Where an RFC 3339 compliant time string has a time-zone other than UTC, it is shifted to UTC. For example, the time string "14:10:20+01:00" is shifted to "13:10:20Z".

Result Coercion

Javascript Date instances are coerced to an RFC 3339 compliant time string by extracting the UTC time part. Invalid Date instances raise a field error.

Input Coercion

When expected as an input type, only RFC 3339 compliant time strings are accepted. All other input values raise a query error indicating an incorrect type.

DateTime

A date-time string at UTC, such as 2007-12-03T10:15:30Z, compliant with the date-time format outlined in section 5.6 of the RFC 3339 profile of the ISO 8601 standard for representation of dates and times using the Gregorian calendar.

This scalar is a description of an exact instant on the time-line such as the instant that a user account was created.

This scalar ignores leap seconds (thereby assuming that a minute constitutes of 59 seconds). In this respect it diverges from the RFC 3339 profile.

Where an RFC 3339 compliant date-time string has a time-zone other than UTC, it is shifted to UTC. For example, the date-time string "2016-01-01T14:10:20+01:00" is shifted to "2016-01-01T13:10:20Z".

Result Coercion

JavaScript Date instances and Unix timestamps (represented as 32-bit signed integers) are coerced to RFC 3339 compliant date-time strings. Invalid Date instances raise a field error.

Input Coercion

When expected as an input type, only RFC 3339 compliant date-time strings are accepted. All other input values raise a query error indicating an incorrect type.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].