You can use a custom scallar that parse the Int into date If you are using apollo server you can try something like this
import { GraphQLScalarType } from 'graphql';
import { Kind } from 'graphql/language';
const resolverMap = {
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;
},
}),
};
And then
scalar Date
type MyType {
created: Date
}
You can take a closer look here https://www.apollographql.com/docs/graphql-tools/scalars/
Here are some other useful scalars https://github.com/Urigo/graphql-scalars