AWS Amplify: The variables input contains a field name that is not defined for input object type

AWS Amplify: The variables input contains a field name that is not defined for input object type


6

I dont understad what happen here.

This is my schema:

type MonthResume @model @auth(rules: [{allow: owner, identityClaim: "sub"}]){
   id: ID!
   incomes: Float!
   spendingByCategory: [Category]
}

type Category @model @auth(rules: [{allow: owner, identityClaim: "sub"}]){
  id: ID!
  name: String!
  amount: Float!
}

This is the autogenerated update mutation that Amplify gives to me:

export const updateMonthResume = /* GraphQL */ `
  mutation UpdateMonthResume(
  $input: UpdateMonthResumeInput!
  $condition: ModelMonthResumeConditionInput
 ) {
 updateMonthResume(input: $input, condition: $condition) {
  id
  incomes
  spendingByCategory {
    id
    name
    amount
    createdAt
    updatedAt
    owner
  }
  createdAt
  updatedAt
  owner
}
}
`;

And this is my input:

{
  "input": {
    "id": "d7f-ee2971fd3ae5",
    "incomes": 220,
    "spendingByCategory": null,
    "createdAt": "2020-08-15T17:06:22.192Z",
    "updatedAt": "2020-08-15T17:06:22.192Z",
    "owner": "subId"
  }
}

I just want update the incomes amount, fot that reason I call the api in this way:

const input = {
  incomes: 0,
}

await API.graphql(graphqlOperation(updateMonthResume, input));

And then, I got the error.

I dont understand, I dont want to update more than the income, does I need change my input? But I sent a null (Amplify does automatically) for the objetc spendingByCategory.

input CreateMonthResumeInput {
   id: ID
   incomes: Float!

}

3

  • 1

    input object can only have properties defined in UpdateMonthResumeInput type, no more – can be less (if nullable/not required) – but all required

    – xadm

    Aug 15, 2020 at 17:29


  • The rest of properties are defined by Amplify by default (createdAt, updatedAd and owner). The problem is that I just want and input with the property that I want to update, no more, but when Amplify sent the input, it add spendingByCategory as null and that give me the error.

    – BigBugCreator

    Aug 15, 2020 at 17:34

  • 1

    UpdateMonthResumeInput defs?

    – xadm

    Aug 15, 2020 at 17:35

4 Answers
4


5

To summarize comment’s discussion/accumulate knowledge:

input object can only have properties defined in UpdateMonthResumeInput type,

  • no more
  • can be less (if nullable/not required)
  • … but all required

usually there is a difference between:

  • input types (used for mutation as input/params)
  • … and return types (result types for queries and mutations)

… and related questions/answers:

Why in this input doesn’t show the property spendingByCategory?

Because it’s not the MonthResume body (own type fields/properties) – it’s from relation … like create user then add user firend – no possibility to create user with friends at once – no nested mutation supported.

if I want to add an array of objects, without relationship, what should specify? I set spendingByCategory: [Category!] just because I did’t find the type Object

Every [query/mutation] depth level needs to be a defined, separate type (and relation between types) in graphql. You can use ‘customJSON type‘ (any serializable or unknown type content) without defining types for complex fields/properties.

1

  • Very good resume about what happen, the log can be confuse.

    – BigBugCreator

    Aug 18, 2020 at 15:06


1

Ok, I solve the problem.

Is nothing related with the SpendingCategory (thats the log I receive and I was searching the problem with that reference).

I had bad input properties and for that reason it dispatch that error.

Be sure that you input object is totally correct before loose time with other logs.

9

  • 1

    to be complete … your UpdateMonthResumeInput defs was…?

    – xadm

    Aug 16, 2020 at 15:29

  • The correct input is without owner, createdAt and updateAt. That properties are on the mutation that Amplify generates, but you dont need to send them when you dispatch the mutation because Amplify does for you, that was my problem.

    – BigBugCreator

    Aug 17, 2020 at 11:25


  • 1

    usually thats the difference between input types (used for mutation as input/params) and return types (result types for queries and mutations) – it was in generated input type ? can you show UpdateMonthResumeInput defs?

    – xadm

    Aug 17, 2020 at 14:25

  • 1

    no, still not the right def (mutation one was already here) 🙂 it should be like input UpdateMonthResumeInput – you can also get it from graphiql docs

    – xadm

    Aug 18, 2020 at 11:05


  • 1

    because it's not 'the MonthResume body` – it's from relation … like create user then add user firend – no possibility to create user with friends at once – no nested mutation supported

    – xadm

    Aug 18, 2020 at 11:54


0

I ran into this problem with a Lambda function and found that in order to pass in the correct user properties (owner) I had to define the input object in the graphql.schema to include the owner – the owner gets passed in from the client to the lambda function that creates the database record. Not sure who the owner would be if left to graphql since the api call is from the lambda function.


0

I encountered with the same problem , in my case when I queried data, amplify puts "__typename" field. If I make edits on this object and send directly using update mutation then this error occurs. In order to get rid of this , I deleted "__typename" property.



Leave a Reply

Your email address will not be published. Required fields are marked *