Created
January 23, 2020 05:24
-
-
Save jelorivera08/0becf53746a93aedb612a1c3309d9539 to your computer and use it in GitHub Desktop.
This file contains 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
/* eslint-disable no-unused-vars */ | |
const { noteType } = require('../nodeTypes'); | |
const { | |
GraphQLString, | |
GraphQLBoolean, | |
GraphQLInt, | |
GraphQLID | |
} = require('graphql'); | |
const NoteService = require('../../services/NoteService'); | |
const CreateNoteMutation = { | |
type: noteType, | |
args: { | |
content: { type: GraphQLString } | |
}, | |
resolve: async (_, { content }) => { | |
const noteService = new NoteService(); | |
const newNote = await noteService.createNote({ content }); | |
return newNote; | |
} | |
}; | |
const DeleteNoteMutation = { | |
type: GraphQLID, | |
args: { | |
_id: { type: GraphQLID } | |
}, | |
resolve: async (_, { _id }) => { | |
const noteService = new NoteService(); | |
const res = await noteService.deleteNote(_id); | |
if (res.ok) { | |
return _id; | |
} | |
} | |
}; | |
const UpdateNoteMutation = { | |
type: noteType, | |
args: { | |
_id: { type: GraphQLID }, | |
content: { type: GraphQLString } | |
}, | |
resolve: async (_, { _id, content }) => { | |
const noteService = new NoteService(); | |
const updatedNote = await noteService.updateNote(_id, { content }); | |
return updatedNote; | |
} | |
}; | |
module.exports = { CreateNoteMutation, UpdateNoteMutation, DeleteNoteMutation }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment