Created
August 2, 2019 21:30
-
-
Save Ajeo/1ab4b3c7530a5f873fcf19f6e69a3117 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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