Prisma-client-js: Automatically serialize a non ISO date string if it is serializable by javascript date object

Created on 21 Apr 2020  Â·  4Comments  Â·  Source: prisma/prisma-client-js

Problem

Only ISO 8061 date string is automatically serialized right now.

Solution


We should allow any date string that is serializable by js Date object.

Additional context


Related: #656, #212

kinfeature tectypescript

Most helpful comment

And that is also what I did now. You can check it out on alpha.
From now on, not only "2020-05-05T16:34:44.719Z" but also "2020-05-05T16:34:44.719+03:00" is allowed.

All 4 comments

Had a closer look at the user's request in #656 and talked to @timsuchanek about this.

Tim noted that we can't simply accept all dates parse-able by new Date(), because they won't take into account timezones. For example new Date("March 13") will parse but uses the system's timezone which may change between server and client. In fact, the only time we can safely parse with new Date() and will not suffer from timezone issues are ISO 8601 strings.

The problem is that we're not properly handling all types of ISO 8601, we're only handling the UTC version.

We should accept the following example formats:

2020-05-04T14:05:23Z
2020-05-04T14:05:23+00:00
2020-05-04T14:05:23+03:00
2020-05-04T14:05:23-10:00

But we only accept:

2020-05-04T14:05:23Z

Thanks @matthewmueller I 100% agree! I think we should just add support for the missing ISO 8601 formats here, that's it.

And that is also what I did now. You can check it out on alpha.
From now on, not only "2020-05-05T16:34:44.719Z" but also "2020-05-05T16:34:44.719+03:00" is allowed.

I'm using a @prisma/client version of 2.0.0-previewnull-1 but when I use a Mutation like this:

mutation {
  createOneComplaint(data: {
    site: "test"
    status: "resolved"
    link: "test.com/test"
    name: "Lloyd Jones"
    publication: "Test"
    decision: "upheld"
    clause: "3"
    dateReceived: "2019-12-09T15:16:03+00:00"
    dateConcluded: "2020-01-01T09:11:34+00:00"
  }) {
    id
  }
}

I get:

"\nInvalid `prisma.complaint.create()` invocation in\n/Users/joneslloyd/Dropbox (BAY.A)/Mac/Documents/personal/development/testsite/node_modules/nexus-prisma/src/builder.ts:315:20\n\n  311   })\n  312 }\n  313 return photon[mappedField.photonAccessor][\n  314   mappedField.operation\n→ 315 ](args\n\n\nInvalid `prisma.complaint.create()` invocation:\n\n{\n  data: {\n    site: 'test',\n    status: 'resolved',\n    link: 'test.com/test',\n    name: 'Lloyd Jones',\n    source: 'Customer',\n    decision: 'upheld',\n    clause: '3',\n    dateReceived: '2019-12-09T15:16:03+00:00',\n                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~\n    dateConcluded: '2020-01-01T09:11:34+00:00'\n                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~\n  }\n}\n\nArgument dateReceived: Got invalid value '2019-12-09T15:16:03+00:00' on prisma.createOneComplaint. Provided String, expected DateTime.\nArgument dateConcluded: Got invalid value '2020-01-01T09:11:34+00:00' on prisma.createOneComplaint. Provided String, expected DateTime.\n\n

A more readable version:

Provided String, expected DateTime

UPDATE:

This issue was solved thanks to the steps outlined here. So technically the issue doesn't exist, because I'm now using the alpha.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

divyenduz picture divyenduz  Â·  3Comments

AhmedElywa picture AhmedElywa  Â·  4Comments

divyenduz picture divyenduz  Â·  4Comments

FluorescentHallucinogen picture FluorescentHallucinogen  Â·  3Comments

samrith-s picture samrith-s  Â·  3Comments