Skip to content
This repository has been archived by the owner on Jan 14, 2021. It is now read-only.

Automatically serialize a non ISO date string if it is serializable by javascript date object #658

Closed
pantharshit00 opened this issue Apr 21, 2020 · 4 comments
Assignees
Labels
kind/feature A request for a new feature. tech/typescript Issue for tech TypeScript.
Milestone

Comments

@pantharshit00
Copy link
Contributor

pantharshit00 commented Apr 21, 2020

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

@schickling schickling added kind/feature A request for a new feature. team/product labels Apr 21, 2020
@schickling schickling added the process/candidate Candidate for next Milestone. label Apr 21, 2020
@janpio janpio added this to the Beta 4 milestone Apr 21, 2020
@janpio janpio removed the process/candidate Candidate for next Milestone. label Apr 21, 2020
@janpio janpio added the tech/typescript Issue for tech TypeScript. label Apr 30, 2020
@divyenduz divyenduz added process/next-milestone and removed tech/typescript Issue for tech TypeScript. labels Apr 30, 2020
@janpio janpio added the tech/typescript Issue for tech TypeScript. label Apr 30, 2020
@matthewmueller matthewmueller self-assigned this Apr 30, 2020
@divyenduz divyenduz modified the milestones: Beta 4, Beta 5 May 4, 2020
@matthewmueller
Copy link
Contributor

matthewmueller commented May 4, 2020

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

@timsuchanek
Copy link
Contributor

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

@timsuchanek
Copy link
Contributor

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.

@joneslloyd
Copy link

joneslloyd commented May 7, 2020

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:

"\n�[31mInvalid �[1m`prisma.complaint.create()`�[22m invocation in�[39m\n�[31m�[4m/Users/joneslloyd/Dropbox (BAY.A)/Mac/Documents/personal/development/testsite/node_modules/nexus-prisma/src/builder.ts:315:20�[24m�[39m\n\n�[2m  �[90m311 �[39m  �[38;2;107;139;140m}�[39m�[38;2;107;139;140m)�[39m�[22m\n�[2m  �[90m312 �[39m�[38;2;107;139;140m}�[39m�[22m\n�[2m  �[90m313 �[39m�[36mreturn�[39m photon�[38;2;107;139;140m[�[39mmappedField�[38;2;107;139;140m.�[39mphotonAccessor�[38;2;107;139;140m]�[39m�[38;2;107;139;140m[�[39m�[22m\n�[2m  �[90m314 �[39m  mappedField�[38;2;107;139;140m.�[39moperation�[22m\n�[31m�[1m→�[22m�[39m �[90m315 �[39m�[38;2;107;139;140m]�[39m�[38;2;107;139;140m(�[39margs\n\n\n�[31mInvalid �[1m`prisma.complaint.create()`�[22m invocation:�[39m\n\n{\n  data: {\n    site: �[2m'test'�[22m�[2m,�[22m\n�[2m�[22m    status: �[2m'resolved'�[22m�[2m,�[22m\n�[2m�[22m    link: �[2m'test.com/test'�[22m�[2m,�[22m\n�[2m�[22m    name: �[2m'Lloyd Jones'�[22m�[2m,�[22m\n�[2m�[22m    source: �[2m'Customer'�[22m�[2m,�[22m\n�[2m�[22m    decision: �[2m'upheld'�[22m�[2m,�[22m\n�[2m�[22m    clause: �[2m'3'�[22m�[2m,�[22m\n�[2m�[22m    dateReceived: �[91m'2019-12-09T15:16:03+00:00'�[39m�[2m,�[22m\n                  �[91m~~~~~~~~~~~~~~~~~~~~~~~~~~~�[39m\n�[2m�[22m    dateConcluded: �[91m'2020-01-01T09:11:34+00:00'�[39m�[2m�[22m\n                   �[91m~~~~~~~~~~~~~~~~~~~~~~~~~~~�[39m\n�[2m�[22m  }�[2m�[22m\n�[2m�[22m}\n\nArgument �[1mdateReceived�[22m: Got invalid value �[91m'2019-12-09T15:16:03+00:00'�[39m on �[1mprisma.createOneComplaint�[22m. Provided �[91mString�[39m, expected �[92mDateTime�[39m.\nArgument �[1mdateConcluded�[22m: Got invalid value �[91m'2020-01-01T09:11:34+00:00'�[39m on �[1mprisma.createOneComplaint�[22m. Provided �[91mString�[39m, expected �[92mDateTime�[39m.\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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/feature A request for a new feature. tech/typescript Issue for tech TypeScript.
Projects
None yet
Development

No branches or pull requests

7 participants