Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Time type not compatible between graphql and sequelize. #141

Open
vsuaste opened this issue Jul 29, 2020 · 2 comments
Open

Time type not compatible between graphql and sequelize. #141

vsuaste opened this issue Jul 29, 2020 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@vsuaste
Copy link

vsuaste commented Jul 29, 2020

GraphqlTime type from graphql-iso-date is not compatible with Sequelize time type.
The problem is that when graphql parses a time type it actually creates a Date with the current day and the time provided by the user. The following code is taken from the graphql-iso-date library

// Parses an RFC 3339 compliant time-string into a Date.
// It does this by combining the current date with the time-string
// to create a new Date instance.
//
// Example:
// Suppose the current date is 2016-01-01, then
// parseTime('11:00:12Z') parses to a Date corresponding to
// 2016-01-01T11:00:12Z.
export const parseTime = (time: string): Date => {
  const currentDateString = new Date().toISOString()
  return new Date(currentDateString.substr(0, currentDateString.indexOf('T') + 1) + time)
}

When we pass to sequelize a time already parsed by graphql, then it will throw an error like this one:

SequelizeDatabaseError: invalid input syntax for type time: "2020-07-29T10:15:30.000+00:00"

And the error is because Sequelize expects only to receive a time type such as 10:15:30Z.
The curious thing is that the same happens for Date type, graphql parses and automatically add the time extra info, but sequelize is capable to extract only the Date.

@vsuaste vsuaste added the bug Something isn't working label Jul 29, 2020
@asishallab
Copy link
Member

It appears the library we use is buggy. I don't see where adding a date to a time is correct behavior. As the new repository is doing the same, let's not use that either. Luckily it seems to be easy to define and implement home rolled scalar types like Date, DateTime, Time, Aliens

Look at these resources:

How to solve this

We implement our own Date, DateTime, and Time scalars. We need to take into account AJV validation (see above).

@asishallab
Copy link
Member

For now remove Time from our global schema, because it appears wrong (to @asishallab) that a ISO-Time is converted to an instance with a Date. The latter actually causes trouble when being fed into Sequelize.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants