A very common use case in GraphQL is creating an object with a mutation, and receiving the exact same fields back, plus and ID returned by the database. Here's a related question asking about this.
My question is, how can this pattern be simplified to avoid repeated fields? I've tried reusing the input type as a fragment,
input ClientInput {
short_name: String
full_name: String
address: String
email: String
location: String
}
type Client {
id: String
...ClientInput
}
...but that failed with
Syntax Error: Expected Name, found ...
All the documentation and blog posts I've seen on Fragments always creates them on
an existing type. That means still repeating all but the ID field:
type Client {
_id: String
short_name: String
full_name: String
address: String
email: String
location: String
}
fragment ClientFields on Client {
short_name: String
full_name: String
address: String
email: String
location: String
}
input ClientInput {
...ClientFields
}
How is that any better?