Working version
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
import { GraphQLScalarType } from 'graphql';
|
||||
import { Kind } from 'graphql/language';
|
||||
|
||||
export const DateTimeScalar = new GraphQLScalarType({
|
||||
name: 'DateTime',
|
||||
description: 'Date custom scalar type',
|
||||
parseValue(value) {
|
||||
return new Date(value); // value from the client
|
||||
},
|
||||
serialize(value) {
|
||||
return new Date(value).toISOString(); // value sent to the client
|
||||
},
|
||||
parseLiteral(ast) {
|
||||
if (ast.kind === Kind.INT) {
|
||||
return parseInt(ast.value, 10); // ast value is always in string format
|
||||
}
|
||||
return null;
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,9 @@
|
||||
import orders from './order';
|
||||
import { DateTimeScalar } from './datetime-type';
|
||||
|
||||
const resolvers = {
|
||||
Query: { ...orders },
|
||||
DateTime: DateTimeScalar,
|
||||
};
|
||||
|
||||
export default resolvers;
|
||||
@@ -0,0 +1,7 @@
|
||||
// (parent, args, ctx, info)
|
||||
const orders = {
|
||||
orders: (_, __, { dataSources }) => dataSources.orderApi.getOrders(),
|
||||
order: (_, { id }, { dataSources }) => dataSources.orderApi.getOrder(id),
|
||||
};
|
||||
|
||||
export default orders;
|
||||
Reference in New Issue
Block a user