0

I am very new to the amplify/react world and stuck on below.

How do I attach an existing item in the create form?

I have two data models with a 1:1 relationship. In the autogenerated create form I do not see an option to attached an existing pickupaddresses. In Amplify studio when I navigate to Content management, somehow amplify adds that functionality ("Add Item") in the content creation form. I want to replicate what content creation form looks like

type ShippingLabel @model @auth(rules: [{allow: owner}]) {
  id: ID!
  ordernumber: String!
  addressline1: String
  addressline2: String
  city: String
  postalcode: String
  country: String
  status: deliverystatus
  customerName: String
  customerPhone: AWSPhone
  customerEmail: AWSEmail
  customerNotes: String
  PickupAddresses: PickupAddresses @hasOne
}


type PickupAddresses @model @auth(rules: [{allow: owner}]) {
  id: ID!
  addressline1: String
  addressline2: String
  city: String
  postalcode: String
  country: String
}

Auto-generated form (No option to associate pickup address) Auto generated form

Content Management form in amplify studio (has an option to search and add a pick up address)

Create content form - desired behavior

Couldn't find a document or post in updating the autogenerated forms

1 Answers1

0

Following the example provided by the AWS Amplify documentation, your code is correct.

Example Code:

type Project @model {
  id: ID!
  name: String
  team: Team @hasOne
}

type Team @model {
  id: ID!
  name: String!
}

To create the mutation on the front-end, the example they have provided is this:

mutation CreateProject {
  createProject(input: {projectTeamId: "team-id", name: "Some Name"}) {
    team {
      name
      id
    }
    name
    id
  }
}

You can now follow the mutations documentation to ensure you create the request accurately, to meet the desired use-case.

Luke
  • 761
  • 1
  • 18