在 graphql 模式中,如何创建同一模型的 parent/child 关系?

In graphql schema, how can I create a parent/child relationship of same model?

我需要创建一个可搜索列表 table,其中一些记录的类型为 ORGANIZATIONRESOURCE。关系是一对多的。因此,一个组织可以拥有许多资源。如何在一个模型下建立这种关系?

使用 AWS Amplify GraphQL API...

像这样? schema.graphql

enum ListingType {
  ORGANIZATION
  RESOURCE
}
type Listing @model {
  id: ID!
  title: String!
  type: ListingType!
  orginzation: Listing
}

然而,在 Mutations 中,我在创建我的第一个资源时无法引用父组织:

您需要为属于关系的任何字段包含一个 @connection 指令,如 docs 中所述。在这种情况下,这样的事情应该有效:

type Listing @model {
  id: ID!
  title: String!
  type: ListingType!
  organization: Listing @connection
}