5

I am trying to create an object with a relationship.

I am using the auto generated amplify mutations

When I create an object without the relationship the operation succeeds. When I create an object with the relationship the operation fails.

The error message I get is

"The variables input contains a field name 'customer' that is not defined for input object type 'CreateCreditcardInput' "

The auto generated mutation is below.

export const createCreditcard = `mutation CreateCreditcard($input: CreateCreditcardInput!) {
  createCreditcard(input: $input) {
    id
    number
    expiration
    customer {
      id
      firstName
      lastName
      phone
      address1
      address2
      city
      state
      postcode
      email
      creditcards {
        nextToken
      }
    }
    payment {
      id
      paymentType
      creditcard {
        id
        number
        expiration
      }
      orderAmount
      order {
        id
        date
        orderStatus
      }
    }
  }
}
`;

1 Answer 1

2

The solution was to change the property that contained the relationship ID from a nested object to a string.

The original that produced the error was

{id: "", number: 1212112, expiration: "12/20", customer: {id:"81d86584-e031-41db-9c20-e6d3c5b005a6"}}

The correction that now works is

{id: "", number: 1212112, expiration: "12/20", creditcardCustomerId: "81d86584-e031-41db-9c20-e6d3c5b005a6"}
Sign up to request clarification or add additional context in comments.

2 Comments

Such basic functionality for submitting an update. It seems aws-amplify should handle that for us, right? I gotta believe there is a way to transform the model as I'm using the same one that came from the query I'm now updating. 🤔
The best idea I can come up with is to write a function that takes a nested object then flattens it to comply with what aws-amplify wants. The nested object's property tree would accumulate into a string. So in this exmple creditcard.customer.id => creditcardCustomerId

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.