-
Notifications
You must be signed in to change notification settings - Fork 172
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
How can we handle Date in graphql and sequelize? #375
Comments
However you like really. |
I end up using this solution graphql/graphql-js#497 Thanks |
@mickhansen seems to me this package should be using custom scalars for dates and timestamps. Would you accept a PR for that? It would be a breaking change... |
At the very least I'm surprised that |
@mickhansen also considering that this package provides its own JSON scalar type, it's kind of odd that it doesn't provide types for all sequelize |
We have this: import { GraphQLScalarType, Kind } from 'graphql';
export const DateType = new GraphQLScalarType({
name: 'Date',
parseLiteral(ast) {
if (ast.kind === Kind.INT) {
return parseInt(ast.value, 10);
}
return null;
},
parseValue(value: string): Date {
return new Date(value);
},
serialize(value: string | Date): string {
return typeof value === 'string' ? value : value.toISOString();
},
}); // ISO Dates for all Sequelize.Date fields
typeMapper.mapType(type => (type instanceof Sequelize.DATE ? DateType : false)); Don't remember where we got it, but the output is basically:
Might be worth shoving into this library as |
GraphQL is handling the serialization at the moment, that seems consistent to me. |
No description provided.
The text was updated successfully, but these errors were encountered: