First you have to define the scalar type in the GraphQL schema:
scalar Date
Then you have to provide a resolver for the scalar type. Here's an example implementation using Luxon:
import { DateTime } from 'luxon';
makeExecutableSchema({
typeDefs: typeDefs,
resolvers: {
Date: new GraphQLScalarType({
name: 'Date',
description: 'Date custom scalar type',
parseValue(value) {
return DateTime.fromISO(value);
},
serialize(value) {
return value.toUTC().toISO();
},
parseLiteral(ast) {
if (ast.kind === Kind.STRING) {
return DateTime.fromISO(ast.value);
}
return null;
},
}),
},
// Rest of the resolvers / mutators / queries here
});
@MikeRyanDev this makes sense on the server side and works. You also need to add the resolver for Date to the client, right?