0

I have created this GraphQL schema and passed it to AppSync via Amplify:

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

type Team @model {
  id: ID!
  title: String!
  members: [Member]
}

and AWS Amplify has generated the following mutation for team update:

export const updateTeam = /* GraphQL */ `
  mutation UpdateTeam(
    $input: UpdateTeamInput!
    $condition: ModelTeamConditionInput
  ) {
    updateTeam(input: $input, condition: $condition) {
      id
      name
      ...
    }
  }
`;

I'm wanting to update the Team via:

  const doSomething = async (id) => {
    try {
      const team = teams[id];
      team.title = // new title

      // cut off automatically added bits

      const teamData = await API.graphql(
        graphqlOperation(updateTeam, { input: team })
      );

    } catch (error) {
      console.error(`Mutation failed`, error);
    }
  };

I am reading the team successfully and I can see that members is a part of the team object. However, it raises an error:

message: "The variables input contains a field name 'members' that is not defined for input object type 'UpdateTeamInput' "

Where and how should I fix this? I mean do I have to go with something like:

...
graphqlOperation(updateTeam, { input: team, members: team.members })
...

although I'm not touching the members object in team[id]?

Manny
  • 679
  • 5
  • 12

1 Answers1

1

This is because you haven't define Member as input type in your graphql schema instead you have defined it as type type.

Define member input type like this:

input MemberInput {
  id: ID!
  name: String!
}

in your graphql schema, it would work then.

Note that if your types are custom than arguments in graphql should be of input type and the return values of type type.

Raghu Chahar
  • 1,637
  • 2
  • 15
  • 33
  • This is problematic as the "model" directive cannot be used on input objects. Amplify CLI will explicitly throw an error and blocks the push operation. – Manny Jul 02 '21 at 04:56
  • @Manny then declare one more input type and use that in further schema, please check updated answer – Raghu Chahar Jul 02 '21 at 05:11