diff --git a/README.md b/README.md index e8ffdc0..6ae3a97 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ ## GraphQL Server Todo +- [with-mongoose](https://github.com/sergeyyarkov/graphql-server-todo/tree/with-mongoose) + ### 🚀 Start Server: ```bash diff --git a/src/graphql/typeDefs/mutation.js b/src/graphql/typeDefs/mutation.js index 9bf944f..4b768fb 100644 --- a/src/graphql/typeDefs/mutation.js +++ b/src/graphql/typeDefs/mutation.js @@ -35,6 +35,45 @@ const Mutation = new GraphQLObjectType({ }).save() }, }, + deleteCategory: { + type: CategoryType, + args: { + id: { type: new GraphQLNonNull(GraphQLID) } + }, + resolve(parent, args) { + return Categories.findByIdAndRemove(args.id) + } + }, + deleteNote: { + type: NoteType, + args: { + id: { type: new GraphQLNonNull(GraphQLID) } + }, + resolve(parent, args) { + return Notes.findByIdAndRemove(args.id) + } + }, + updateCategory: { + type: CategoryType, + args: { + id: { type: new GraphQLNonNull(GraphQLID) }, + title: { type: new GraphQLNonNull(GraphQLString) } + }, + resolve(parent, args) { + return Categories.findByIdAndUpdate(args.id, { $set: { title: args.title } }, { new: true }) + } + }, + updateNote: { + type: NoteType, + args: { + id: { type: new GraphQLNonNull(GraphQLID) }, + title: { type: new GraphQLNonNull(GraphQLString) }, + categoryId: { type: new GraphQLNonNull(GraphQLID) } + }, + resolve(parent, args) { + return Notes.findByIdAndUpdate(args.id, { $set: { title: args.title, categoryId: args.categoryId } }, { new: true }) + } + } }, }) diff --git a/src/server.js b/src/server.js index 71919bc..5ea8e7b 100644 --- a/src/server.js +++ b/src/server.js @@ -9,8 +9,8 @@ const PORT = 3001 server.use('/graphql', graphqlHTTP({ schema, graphiql: true })) mongoose.connect( - 'mongodb+srv://sergeyyarkov:1234@cluster0-1dsll.mongodb.net/todo-db?retryWrites=true&w=majority', - { useNewUrlParser: true, useUnifiedTopology: true } + 'mongodb+srv://user:password@cluster0-1dsll.mongodb.net/todo-db?retryWrites=true&w=majority', + { useNewUrlParser: true, useUnifiedTopology: true, useFindAndModify: false } ) mongoose.connection.on('error', (err) =>