-
-
Notifications
You must be signed in to change notification settings - Fork 676
Proposal: Date support #22
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
Comments
Honestly, I prefer the ISO version of the Date scalar, it's human readable and easier to debug: import { GraphQLScalarType, Kind } from "graphql";
export const DateScalar = new GraphQLScalarType({
name: "Date",
description: "Date scalar type",
parseValue(value: string) {
return new Date(value); // value from the client input variables
},
serialize(value: Date) {
return value.toISOString(); // value sent to the client
},
parseLiteral(ast) {
if (ast.kind === Kind.STRING) {
return new Date(ast.value); // value from the client query
}
return null;
},
}); And because I don't want to make this framework so opinionated, I prefer to gave developers freedom to use their own version of |
You are right. I will change it to the iso format.
|
A default date speeds up the getting started, but of course, passing in the custom scalar type as presented by you is just fine too: import { GraphQLScalarType, Kind } from 'graphql';
import { Field, GraphQLObjectType } from 'type-graphql';
export const DateScalar = new GraphQLScalarType({
name: 'Date',
description: 'Date scalar type',
parseValue(value: string) {
return new Date(value); // value from the client input variables
},
serialize(value: Date) {
return value.toISOString(); // value sent to the client
},
parseLiteral(ast) {
if (ast.kind === Kind.STRING) {
return new Date(ast.value); // value from the client query
}
return null;
}
});
@GraphQLObjectType()
export class User {
@Field(type => DateScalar)
contributorsince: Date;
@Field()
alive: boolean;
} |
Closing - implemented in ba21848 😉 |
I propose to add Date support using this implementation, found here graphql/graphql-js#550
The text was updated successfully, but these errors were encountered: