如何使用 graphql 改变嵌套对象

How to mutate nested object using graphql

我有一个如下所示的猫鼬模式:

import mongoose from 'mongoose'

const ProjectSchema = new mongoose.Schema({
  name: {
    type: String
  },
  owner: {
    type: String
  },
  member: {
    type: String
  },
  updatedDate: {
    type: Date
  },
  description: {
    type: String
  },
  folder: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'Folder'
  },
  dataSources: [{
    name: {
      type: String
    },
    updatedDate: {
      type: Date
    },
  }],
  propjectHistory: [{
    no: {
      type: Number
    },
    member: {  // is this reference or just a string?
      type: String
    },
    action: {
      type: String
    },
    updatedDate: {
      type: Date
    },
  }]
})

const Project = mongoose.model('Project', ProjectSchema)

并且我使用 graffiti 和 graffiti-mongoose 与 graphql 集成。 但是,Graphiql 文档显示我只有以下那些:

addProject(input: addProjectInput!):

name: String
owner: String
member: String
updatedDate: Date
description: String
folder: ID
clientMutationId: String!

我可以仅使用这些参数成功添加带有突变查询的项目,但似乎我什至无法发送带有嵌入在项目架构中的 projectHistory 和 dataSource 的突变查询。

但是,当我发送查找查询时,我可以访问 projectHistory 和 dataSource。

我找不到关于该问题的任何文档。

没有嵌套查询的示例变异查询有效。

mutation {
  addProject(input:{
    clientMutationId: "1"
    name: "testproject",
    owner: "keonwoo",
    member: "keonwoo",
    updatedDate: "2015-07-24T13:23:15.580Z",
    description: "this is test project",
    folder: "56fb93403eab9e1c14358fb7"
  }){
    clientMutationId
    changedProjectEdge{
      node{
        _id
        name
        updatedDate
      }
    }
  }
}

以上变异returns以下:

{
  "data": {
    "addProject": {
      "clientMutationId": "1",
      "changedProjectEdge": {
        "node": {
          "_id": "56fb93ab3eab9e1c14358fb8",
          "name": "testproject",
          "updatedDate": "2015-07-24T13:23:15.580Z"
        }
      }
    }
  }
}

我没有像中继一样使用客户端。

问题出在 graffiti-mongoose 库上。

原来graffiti-mongoose的维护者刚刚添加了嵌入对象功能,我没有更新。