9

I'm needing to create a searchable listing table where some records are of type ORGANIZATION or RESOURCE. The relationshipis one-to-many. So, an Organization can have many Resources. How can I create this relationship under one model?

Using AWS Amplify GraphQL API...

Like this? schema.graphql

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

Yet, in Mutations, I can't reference a parent organization when creating my first Resource:

enter image description here

Chance Smith
  • 1,211
  • 1
  • 15
  • 32

1 Answers1

2

You need to include a @connection directive for any field that is a relationship, as outlined in the docs. In this case, something like this should work:

type Listing @model {
  id: ID!
  title: String!
  type: ListingType!
  organization: Listing @connection
}
Daniel Rearden
  • 80,636
  • 11
  • 185
  • 183