This commit is contained in:
Sergey Yarkov 2020-06-14 21:05:20 +03:00
parent a7a895648f
commit dcf7f71580
8 changed files with 17 additions and 13 deletions

View File

@ -2,7 +2,6 @@ const mongoose = require('mongoose')
const categorySchema = new mongoose.Schema({
title: String,
description: String,
createdAt: String,
updatedAt: String,
})

View File

@ -5,7 +5,6 @@ const todoSchema = mongoose.Schema({
description: String,
createdAt: String,
updatedAt: String,
status: String,
deadline: String,
categoryId: String,
})

View File

@ -6,10 +6,9 @@ const categoryResolvers = {
category: (_, { id }) => Category.findById(id),
},
Mutation: {
createCategory: (_, { title, description }) => {
createCategory: (_, { title }) => {
const category = new Category({
title,
description,
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
})
@ -19,7 +18,7 @@ const categoryResolvers = {
const deletedCategory = await Category.findByIdAndRemove(id)
return deletedCategory
},
updateCategory: (_, { id, title, description }) => Category.findByIdAndUpdate(id, { $set: { title, description, updatedAt: new Date().toISOString() } }, { new: true })
updateCategory: (_, { id, title }) => Category.findByIdAndUpdate(id, { $set: { title, updatedAt: new Date().toISOString() } }, { new: true })
},
Category: {
todos: ({ id }) => Todo.find({ categoryId: id }),

View File

@ -12,7 +12,6 @@ const todoResolvers = {
description,
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
status: 'open',
deadline,
categoryId,
})
@ -22,7 +21,7 @@ const todoResolvers = {
const deletedTodo = await Todo.findByIdAndRemove(id)
return deletedTodo
},
updateTodo: (_, { id, title, description, status, deadline, categoryId }) => Todo.findByIdAndUpdate(id, { $set: { title, description, updatedAt: new Date().toISOString(), status, deadline, categoryId } }, { new: true }),
updateTodo: (_, { id, title, description, deadline, categoryId }) => Todo.findByIdAndUpdate(id, { $set: { title, description, updatedAt: new Date().toISOString(), deadline, categoryId } }, { new: true }),
},
Todo: {
category: ({ categoryId }) => Category.findById(categoryId),

View File

@ -8,7 +8,17 @@ const port = config.get('port')
const startServer = async () => {
try {
const server = new ApolloServer({ typeDefs, resolvers })
const server = new ApolloServer({
typeDefs,
resolvers,
// context: (integrationContext) => {
// const query = integrationContext.req.query.query || integrationContext.req.body.query || '';
// console.log(query.length)
// if (query.length > 500) {
// throw new Error('Query too large');
// }
// },
});
await mongoose.connect(config.get('db'), {
useNewUrlParser: true,
useUnifiedTopology: true,

View File

@ -5,12 +5,12 @@ const mutation = gql`
# Todo mutations
createTodo(title: String! description: String! deadline: String! categoryId: String!): Todo
deleteTodo(id: ID!): Todo
updateTodo(id: ID! title: String! description: String! status: String! deadline: String! categoryId: String!): Todo
updateTodo(id: ID! title: String! description: String! deadline: String! categoryId: String!): Todo
# Category mutations
createCategory(title: String! description: String!): Category
createCategory(title: String!): Category
deleteCategory(id: ID!): Category
updateCategory(id: ID! title: String! description: String!): Category
updateCategory(id: ID! title: String!): Category
}
`

View File

@ -4,7 +4,6 @@ const categoryType = gql`
type Category {
id: ID
title: String
description: String
createdAt: String
updatedAt: String
todos: [Todo]

View File

@ -7,7 +7,6 @@ const todoType = gql`
description: String
createdAt: String
updatedAt: String
status: String
deadline: String
categoryId: String
category: Category