项目作者: meetup

项目描述 :
js-joda date and time types for GraphQL
高级语言: TypeScript
项目地址: git://github.com/meetup/graphql-joda-types.git
创建时间: 2018-06-27T17:56:13Z
项目社区:https://github.com/meetup/graphql-joda-types

开源协议:MIT License

下载


graphql-joda-types

npm
main
Coverage Status

This is a small JavaScript library allowing you to use the date/time types from js-joda in your GraphQL resolvers.

(We recommend js-joda for all JavaScript date/time code, but if you disagree, consider graphql-iso-date instead of this package.)

Supported Types

The following js-joda types are currently supported:

Usage

Installation is straightforward:

  1. yarn add graphql-joda-types # or use npm

You can then write something like the following in your schema:

  1. scalar LocalDate
  2. scalar ZonedDateTime
  3. scalar ZoneId
  4. type User {
  5. id: ID!
  6. name: String
  7. birthday: LocalDate
  8. timezone: ZoneId
  9. createdAt: ZonedDateTime
  10. updatedAt: ZonedDateTime
  11. }

And then in your GraphQL server:

  1. import { LocalDate, ZonedDateTime, ZoneId } from 'graphql-joda-types';
  2. import { makeExecutableSchema } from '@graphql-tools/schema';
  3. const schema = makeExecutableSchema({
  4. resolvers: {
  5. LocalDate,
  6. ZonedDateTime,
  7. ZoneId,
  8. // ...
  9. },
  10. });

You will then be able to use js-joda date and time types as you expect in your other resolvers: input types will automatically be parsed to the appropriate object types, and when your resolvers return these types to clients, they will be stringified properly.