mirror of
https://github.com/sergeyyarkov/graphql-server-todo.git
synced 2026-10-11 10:19:27 +03:00
added mutations
This commit is contained in:
parent
d26dae32a1
commit
6fe8b6dbe5
@ -1,5 +1,7 @@
|
|||||||
## GraphQL Server Todo
|
## GraphQL Server Todo
|
||||||
|
|
||||||
|
- [with-mongoose](https://github.com/sergeyyarkov/graphql-server-todo/tree/with-mongoose)
|
||||||
|
|
||||||
### 🚀 Start Server:
|
### 🚀 Start Server:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
|||||||
@ -35,6 +35,45 @@ const Mutation = new GraphQLObjectType({
|
|||||||
}).save()
|
}).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 })
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@ -9,8 +9,8 @@ const PORT = 3001
|
|||||||
server.use('/graphql', graphqlHTTP({ schema, graphiql: true }))
|
server.use('/graphql', graphqlHTTP({ schema, graphiql: true }))
|
||||||
|
|
||||||
mongoose.connect(
|
mongoose.connect(
|
||||||
'mongodb+srv://sergeyyarkov:1234@cluster0-1dsll.mongodb.net/todo-db?retryWrites=true&w=majority',
|
'mongodb+srv://user:password@cluster0-1dsll.mongodb.net/todo-db?retryWrites=true&w=majority',
|
||||||
{ useNewUrlParser: true, useUnifiedTopology: true }
|
{ useNewUrlParser: true, useUnifiedTopology: true, useFindAndModify: false }
|
||||||
)
|
)
|
||||||
|
|
||||||
mongoose.connection.on('error', (err) =>
|
mongoose.connection.on('error', (err) =>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user