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({ const categorySchema = new mongoose.Schema({
title: String, title: String,
description: String,
createdAt: String, createdAt: String,
updatedAt: String, updatedAt: String,
}) })

View File

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

View File

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

View File

@ -12,7 +12,6 @@ const todoResolvers = {
description, description,
createdAt: new Date().toISOString(), createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(), updatedAt: new Date().toISOString(),
status: 'open',
deadline, deadline,
categoryId, categoryId,
}) })
@ -22,7 +21,7 @@ const todoResolvers = {
const deletedTodo = await Todo.findByIdAndRemove(id) const deletedTodo = await Todo.findByIdAndRemove(id)
return deletedTodo 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: { Todo: {
category: ({ categoryId }) => Category.findById(categoryId), category: ({ categoryId }) => Category.findById(categoryId),

View File

@ -8,7 +8,17 @@ const port = config.get('port')
const startServer = async () => { const startServer = async () => {
try { 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'), { await mongoose.connect(config.get('db'), {
useNewUrlParser: true, useNewUrlParser: true,
useUnifiedTopology: true, useUnifiedTopology: true,

View File

@ -5,12 +5,12 @@ const mutation = gql`
# Todo mutations # Todo mutations
createTodo(title: String! description: String! deadline: String! categoryId: String!): Todo createTodo(title: String! description: String! deadline: String! categoryId: String!): Todo
deleteTodo(id: ID!): 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 # Category mutations
createCategory(title: String! description: String!): Category createCategory(title: String!): Category
deleteCategory(id: ID!): 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 { type Category {
id: ID id: ID
title: String title: String
description: String
createdAt: String createdAt: String
updatedAt: String updatedAt: String
todos: [Todo] todos: [Todo]

View File

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