Skip to content

Instantly share code, notes, and snippets.

@Ajeo
Created August 2, 2019 21:30
Show Gist options
  • Save Ajeo/1ab4b3c7530a5f873fcf19f6e69a3117 to your computer and use it in GitHub Desktop.
Save Ajeo/1ab4b3c7530a5f873fcf19f6e69a3117 to your computer and use it in GitHub Desktop.
import { GraphQLScalarType } from "graphql";
import { Kind } from "graphql/language";
export default {
Date: new GraphQLScalarType({
name: "Date",
description: "Date custom scalar type",
parseValue(value) {
return new Date(value); // value from the client
},
serialize(value) {
return value.getTime(); // value sent to the client
},
parseLiteral(ast) {
if (ast.kind === Kind.INT) {
return new Date(ast.value); // ast value is always in string format
}
return null;
}
})
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment