Last active
April 1, 2020 18:58
-
-
Save kluu1/f22a5d1c621fbdeacb592cf902c8c94e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const { GraphQLScalarType } = require('graphql') ; | |
| const { Kind } = require('graphql/language'); | |
| const orders = require('../db'); | |
| const resolvers = { | |
| Query: { | |
| orders: (_, args) => { | |
| return orders; | |
| } | |
| }, | |
| Mutation: { | |
| addOrder: (_, { userId, amount }) => { | |
| const newOrder = { | |
| userId, | |
| amount, | |
| createdAt: Date.now() | |
| } | |
| orders.push(newOrder); | |
| return newOrder; | |
| } | |
| }, | |
| Date: new GraphQLScalarType({ | |
| name: 'Date', | |
| description: 'Custom date scalar', | |
| parseValue(value) { | |
| return value; | |
| }, | |
| serialize(value) { | |
| return new Date(Number(value)); | |
| }, | |
| parseLiteral(ast) { | |
| if (ast.kind === Kind.INT) { | |
| return new Date(ast.value); | |
| } | |
| return null; | |
| } | |
| }) | |
| }; | |
| module.exports = resolvers; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment