Home Why scalar Date GraphQL doesn't work
Reply: 1

Why scalar Date GraphQL doesn't work

Ramzan Chasygov
1#
Ramzan Chasygov Published in 2018-01-11 02:32:54Z

I have project where I use graphql and need provide date thought graphql, when I use String type date properly shows in resolver, but when I use scalar Date in resolver I get false intead date. In docs find nothing. Date provided as Wed Jan 11 2018 21:30:00. Should I install moment cause I get warning eprecation warning: value provided is not in a recognized RFC2822 or ISO format. moment construction falls back to js Date() and I don't use moment in my project.

/*---- doesn't work ----*/
scalar Date
type Event {
  id: ID!
  title: String!
  dateStart: Date!
  dateEnd: Date!
  users: [User]
  room: Room
}
input EventInput {
  title: String!
  dateStart: Date!
  dateEnd: Date!
}

/*---- works ----*/
type Event {
  id: ID!
  title: String!
  dateStart: String!
  dateEnd: String!
  users: [User]
  room: Room
}
input EventInput {
  title: String!
  dateStart: String!
  dateEnd: String!
}

Seena V P
2#
Seena V P Reply to 2018-01-11 04:11:22Z

You have to resolve custom scalar Date in your resolver

Date: {
  __serialize(value) {

    return value; // value sent to the client
  },

  __parseValue(value) {

    return value;
  },
  __parseLiteral(ast) {
    return JSON.parse(JSON.stringify(ast)).value;
  }
}

Add this in your resolver. This may solve your issue

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.298999 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO