Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
162
rated 0 times [  169] [ 7]  / answers: 1 / hits: 14280  / 5 Years ago, mon, march 25, 2019, 12:00:00

I am trying to send a mutation to my graphql server to update a date. My mutation schema looks like this:



mutation CreateReminderMutation(
$birthday: Date
) {
createReminder(
birthday: $birthday
) {
id
}
}


Then in my react component I am sending the date like this using moment.



const Calendar = () => {
// component and mutation implementation
birthday: moment(birthday).toDate()
}


I am getting the following error message:




[GraphQL error]: Message: Variable $birthday got invalid value
2019-03-15T12:00:00.000Z; Expected type Date; Value is not a valid
Date: 2019-03-15T12:00:00.000Z, unparsable, Location: [object Object],
Path: undefined




can anyone advise how to get the correct Date format with moment to send to graphql?


More From » reactjs

 Answers
12

Assuming you're using the graphql-iso-date package, a Date scalar needs to be in the YYYY-MM-DD format. So your mutation would be like:



mutation {
createReminder(birthday: 1990-01-01) {
id
}
}


See this codesandbox: https://m5782nj1w9.sse.codesandbox.io/?query=query%20%7B%0A%20%20daysAgo%28when%3A%20%222018-01-01%22%29%0A%7D


[#8294] Friday, March 22, 2019, 5 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jensenb

Total Points: 634
Total Questions: 102
Total Answers: 102

Location: Bosnia and Herzegovina
Member since Thu, Jun 24, 2021
3 Years ago
jensenb questions
Fri, Dec 10, 21, 00:00, 3 Years ago
Thu, Jun 24, 21, 00:00, 3 Years ago
Wed, Apr 7, 21, 00:00, 3 Years ago
Tue, Jun 4, 19, 00:00, 5 Years ago
Thu, Feb 21, 19, 00:00, 5 Years ago
;