如何使用 GraphQL 将嵌套对象作为参数传递给突变?

How to pass a nested object as an argument to mutation using GraphQL?

因此,我正在编写一个充当 GraphQL 服务器的 node.js 应用程序。我有这样的架构:

type Program {
  _id: ID!
  name: String!
  cover: String!
  groups: [Group]
}

type Group {
  name: String!
  exercises: [Exercise]
}

type Exercise {
  _id: ID!
  name: String!
  tags: [String]
  cover: String!
  images: [String]
  text: String!
}

我需要创建一个包含一些 groupProgramgroup 存储在一个文档中的 Program 中,这就是原因)。

如何将嵌套对象作为参数传递给突变,以便创建嵌套对象?

您要找的是 GraphQLInputObjectType, 这就像 GraphQLObjectType,但适用于输入(参数)

http://graphql.org/docs/api-reference-type-system/#graphqlinputobjecttype

尽情享受吧:)