moongodb структурирование каталога

не могу понять как решить задачу. Есть два модуля:

const mongoose = require('mongoose');

const noteSchema = new mongoose.Schema(
  {
    title: {
      type: String,
      require: true
    },
    category: {
      type: mongoose.Schema.ObjectId,
      ref: 'Cat',
      required: true
    },
    anotation: {
      type: String,
      required: true
    },
    content: {
      type: String,
      required: true
    },
    author: {
      type: String,
      required: true
    }
  },
  {
    timestamps: true
  }
);

const Note = mongoose.model('Note', noteSchema);
module.exports = Note;

и

const mongoose = require('mongoose');

const catSchema = new mongoose.Schema({
  catname: {
    type: String,
    required: true
  },
  nots: [{ type: mongoose.Schema.ObjectId, ref: 'Note' }]
});

const Cat = mongoose.model('Cat', catSchema);
module.exports = Cat;

Cат - разделы заметок Note.

Соответственно схема:

module.exports = gql`
  type Note {
    id: ID!
    title: String!
    category: Cat
    anotation: String
    content: String!
    author: String!
  }

  type Cat {
    catid: ID!
    catname: String!
    nots: [Note]
  }

  type Query {
    notes: [Note!]!
    note(id: ID!): Note!
    categories: [Cat!]!
  }

  type Mutation {
    newNote({
      title: String!
      category: Cat!
      anotation: String!
      content: String!}
    ): Note

    newCat(catname: String!): Cat!
  }
`;

КАК оформить правильно мутацию???? Сейчас у меня выглядит она так:

module.exports = {
  newNote: async (parent, args, { models }) => {
    return await models.Note.create({
      title: args.title,
      category: args.category,
      anotation: args.anotation,
      content: args.content,
      author: 'piter pen'
    });
  },

СПАСИБО!!!!


Ответы (0 шт):