首页 文章

如何使用graphql改变嵌套对象

提问于
浏览
0

我有一个类似下面的mongoose架构:

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)

我使用涂鸦和涂鸦 - 猫鼬与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
      }
    }
  }
}

上述突变返回以下内容:

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

我不是像继电器那样使用客户端 .

1 回答

  • 0

    问题在于涂鸦 - 猫鼬图书馆 .

    事实证明涂鸦猫鼬的维护者只是添加了嵌入式对象功能,我没有更新 .

相关问题