Working version

This commit is contained in:
Niklas Fondberg
2021-04-06 14:53:20 +02:00
parent 4532fbc853
commit 813f4c8e47
8 changed files with 104 additions and 15 deletions
+19
View File
@@ -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;
},
});
+9
View File
@@ -0,0 +1,9 @@
import orders from './order';
import { DateTimeScalar } from './datetime-type';
const resolvers = {
Query: { ...orders },
DateTime: DateTimeScalar,
};
export default resolvers;
+7
View File
@@ -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;