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?
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
No moment.js solution but this works for me using graphql prisma
new Date().toISOString()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With