excitement-engineer / graphql-iso-date

A set of RFC 3339 compliant date/time GraphQL scalar types.
MIT License
523 stars 50 forks source link

How can I use graphql-iso-date with graphql-tag? #110

Open dotku opened 4 years ago

dotku commented 4 years ago

eg I have a type E with following statements

const GraphqlISODate  = require('graphql-iso-date');
const {GraphQLDate} = GraphqlISODate;

module.exports = gql`
type E {
 ... 
 purchaseDate: GraphQLDate
}
`

But I got error with GraphQLDate not found, how can I resolved it?

pixeldrew commented 4 years ago

This URL should help: https://www.apollographql.com/docs/graphql-tools/scalars/

Essentially, define a scalar in your schema as a type GraphQLDate in GQL and add the definition to your resolvers object.

module.exports = gql `
scalar GraphQLDate
type E {
  ...
  purchaseDate: GraphQLDate
}

Then where you define your resolvers import GraphQLDate as a key

resolvers = {
  GraphQLDate,
  ...
}