Imagine that I have this "Schema":
type User {
id: ID!
name: String!
}
Now, in one of my components (A) I need the user id
; and in another component (B) I need the user id
and the user name
.
What I'm doing now is to make a User query in A Component
requesting only the ID. And in B Component
I'm making another User query requesting id and name.
There's a piece of the query that's always the same:
// Component A request
const query = gql`{
User(id: 1) {
id
}
}`
// Component B request
const query = gql`{
User(id: 1) {
id
name
}
}`
That User(id:1){}
is the same and what is suggested to change is the response parameters. What is the correct approach to this? Is correct to duplicate that fixed part of the query?
Our problem is that if in the future the Schema suffers a change, we gonna need to refactor all the queries in all the places they are. What we want is a way to centralize it and parameterize it in order to be scalable in response of Schema changes.
One of my teammates has made a function that receives a string and places it inside the GQL query. I don't like that approach. What do you think?