0

I am in a an appsync environment that has been in production for a while. This is not the first mutation or even mutation taking an array of objects in the project. Yet what has worked for other such cases does not work for this one.

I dimly recall that sometimes a 'complex' argument like an array of objects or even scalars only got past the parse when turned to an input type. LeaderboardEventType below is an enum.

type LeaderboardEventScores {
    event: LeaderboardEventType!
    score: String!
}

type LeaderboardConfigScores {
    id: ID!
    scores: [LeaderboardEventScores]!
}

input LeaderboardConfigScoresInput {
     id: ID!
     scores: [LeaderboardEventScores]!
}

While the type definition above works in the parser the input definition exactly like it does not. I don't see at all why not. And neither of them works to define the argument of my mutation. Nor does adding an inner ! for the input work. Nor does just taking the body of the input with a comma after ID! as mutation arguments. But what really has my goat is that I cannot define such an input. Why not?

Samantha Atkins
  • 658
  • 4
  • 12
  • 1
    Only scalars and enums can be used for both input and output. Object types, interfaces and unions are strictly output types. Input objects are strictly input types. [They are not interchangeable](http://spec.graphql.org/June2018/#sec-Input-and-Output-Types). Please see [this post](https://stackoverflow.com/questions/41743253/whats-the-point-of-input-type-in-graphql) for additional details. – Daniel Rearden Feb 06 '20 at 00:48

1 Answers1

0

I found a solution but darn if it makes a lot of sense to me. If I make an input like the type I am doing an array of as an argument and instead do a an array of the input then it "works".

input LeaderboardEventScoreInput {
  event: LeaderboardEventType!
  score: String!
}

and the mutation

modifyLeaderboardConfigScores(
 id: ID!
 scores: [LeaderboardEventScoreInput]!
): [LeaderboardEventScores]!

So apparently arrays of non-scalars are only supported if the element type is an input.

Samantha Atkins
  • 658
  • 4
  • 12