title: GraphQL Custom scalar type DateScalar
body: <p>This is my Resolvers, typedefs and dateScalar file. I am in the process of creating a custom scalar Date to represent Date for an object when querying through GraphQL.</p>
  <p>resolvers.js</p>
  <pre><code>const dateScalar = require(&quot;./dateScalar&quot;);
  const resolvers = {
  
    DateScalar: {
      dateScalar,
    },
  };
  
  module.exports = resolvers;
  </code></pre>
  <p>dateScalar.js</p>
  <pre><code>module.exports = {
  DateScalar: new GraphQLScalarType({
  name: &quot;DateScalar&quot;,
  description: &quot;Date Scalar type&quot;,
  
  parseValue(value) {
    return new Date(value);
  },
  parseLiteral(ast) {
    if (ast.kind === Kind.INT) {
      // return parseInt(ast.value, 10);
      return new Date(ast.value);
    }
    return null;
  },
  serialize(value) {
    // const date = new Date(value);
    // return date.toISOString();
    return value.getTime();
  },
  }),
  };
  </code></pre>
  <p>typeDef.js</p>
  <pre><code>const {gql} = require(&quot;apollo-server-express);
  const typeDefs = gql`
  scalar DateScalar
  type Item{
  Date: DateScalar
   } `
  </code></pre>