GraphQL 嵌套变异 + Sequelize

GraphQL nested mutation + Sequelize

我正在将 graphQL、sequelize 和 nodejs 与 apollo 客户端一起使用。 我从 UI 发送的数据是以下形式的嵌套结构:

Grandparent

Parent

Child

所以一个 grandparent 可以有一个或多个 parent,一个 parent 可以有一个或多个 children。

我正在尝试更新我的 SQLite 数据库,该数据库是使用 sequelize 创建的,使用一个 GraphQL 突变。我能够创建具有平面结构的突变:

schema.gql 文件内容 ->

type Mutation Family(
    grandParentName: String,
    grandParentHeight: String,
    Parent: String,
)

但我想要类似

的东西
type Mutation CreateNestedFamily(
    grandParentName: String,
    grandParentHeight: String,
    Parent: CreateParent(
           parentName: String,
           parentHeight: String
           child: CreateChild(
                 childName: String,
                 childHeight: String
                 )
            )
)

但我不知道如何实现这一点,而且关于嵌套突变的 graphql 文档非常有限。

如有任何帮助,我们将不胜感激!

您表述问题的方式有点奇怪,但我会尽力为您指明正确的方向。

GraphQL 中没有嵌套突变这样的东西,但您可以构建允许任意嵌套数据的输入类型,然后传递给单个突变。

我会从你的方法中退一步,解决一个具体的问题"I want to create a person and their descendants"

input PersonInput {
  name: String!
  height: String!
  children: [PersonInput!]
}

type Mutation {
  createPerson(person: PersonInput!): SomeOutputType
}

希望你能看出这个结构的递归本质。对此施加限制会更加困难,即只允许 3 层深。