added mutations

This commit is contained in:
Sergey Yarkov 2020-06-05 20:00:12 +03:00
parent d26dae32a1
commit 6fe8b6dbe5
3 changed files with 43 additions and 2 deletions

View File

@ -1,5 +1,7 @@
## GraphQL Server Todo
- [with-mongoose](https://github.com/sergeyyarkov/graphql-server-todo/tree/with-mongoose)
### 🚀 Start Server:
```bash

View File

@ -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 })
}
}
},
})

View File

@ -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) =>