GraphQL queries/mutations are super clean: they only require what they actually require, nothing else. Or at least the basic ones are.
But if you use variables with either one, then your syntax inevitably has redundancy in it:
query HeroNameAndFriends($episode: Episode) {
hero(episode: $episode) {
name
friends {
name
}
}
}
Note the $episode: Episode and episode: $episode. The thing is EVERY GraphQL mutation requires this same redundancy: if you use variables, every argument has to be defined twice (and if you're making programmatic queries, you undoubtedly are using variables).
My question is, why? It seems so unnecessary to make everyone who uses GraphQL have to repeat their arguments a second time.
Why not just make the syntax:
query HeroNameAndFriends() {
hero($episode: Episode) {
name
friends {
name
}
}
}
or if your really need to allow for differing variable names, allow an optional third part:
query HeroNameAndFriends() {
hero(episode: Episode : $episode) {
name
friends {
name
}
}
}
To be clear, I understand that variable-using queries are different from non-variable ones, but what I'm asking about is, why pick a syntax for those queries that forces everyone to repeat themselves?
It just seems so ... not DRY! Surely I'm missing an important reason why this repetition is necessary?