Graphback: Date or DateTime type

Created on 10 Apr 2020  路  7Comments  路  Source: aerogear/graphback

Is there no native date or datetime type? I would really like to have these kinds of types. They should handle date inputs and store themselves in a universal format, like an ISO UTC string or perhaps milliseconds since the unix epoch. Prisma's date (or DateTime?) type stores itself as an ISO UTC string, which has worked very well for me. You can input either a JavaScript date type or a date string, and it all works. Something like that would be nice to have, and seems essential actually.

bug

Most helpful comment

would be great to have date and date-time fields supported!

All 7 comments

Great feedback! We were talking with the team about this.
Generally, we decided that Scalars like Date etc. should be the choice of the template and our current templates do not have any loaded. Graphback itself works as a great addition to existing GraphQL projects that might have scalars.
If we start adding scalars in the core we might get conflicts with already defined one.

Ideally, we should at least have Date, JSONObject and couple others from graphql-scalars in the default template to show that they work quite nicely and test them. In terms of having then out of the box in model I will need to rely on @craicoverflow opinion as this might affect the way we migrate database.

I think this could be a bug to see how database migration will work with scalars and also feature request to have scalars in core or templates

As @wtrocki said - idealy we would like to leave the choice of scalars to the template.

I just tested migrations with graphql-iso-date and the field will only get generated when it has a @db.type: 'timestamp annotation.

Obviously we do not want our users to need to specify an annotation for a DateTime field in their data model for migrations. I think this could be pretty easily resolved by adding custom scalar mapping in the dbmigrations config. Currently the default scalar mappings are embedded into the code (see here).

We could make it simpler again by embedding a default mapping between DateTime and timestamp. This would not require any additional dependencies, but it would just mean that the user does not have to add any additional config.

Related to #1114

It is important to actually support his out of the box so resolver plugin should add date and time resolvers (with ability to suppress it)

Problem is that people will need to do

npm install --save graphql-scalars

Alternative will be to have this embedded into runtime package with ability to get all resolvers. Adding this issue to the most critical we need to solve for the next release

would be great to have date and date-time fields supported!

I can extract the foundational work from https://github.com/aerogear/graphback/pull/1620/files that adds default scalar support.

This was closed for now as there were some issues with JSON filtering which requires further thoughts, but this should not block adding Date/DateTime!

This was closed for now as there were some issues with JSON filtering which requires further thoughts, but this should not block adding Date/DateTime!

Agreed.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wtrocki picture wtrocki  路  6Comments

ankitjena picture ankitjena  路  5Comments

lastmjs picture lastmjs  路  4Comments

b1zzu picture b1zzu  路  4Comments

wtrocki picture wtrocki  路  6Comments