I´m having a relative complex, hierarchical data model in my Spring application and I need to query it as well as update all entities by letting the client pass the changed entity to the server.
Using GraphQL for querying solves exactly my needs, but to enable update and create capabilities however, I´d need to duplicate all my entities as *.graphqls files won´t support using "type" elements as "input" elements.
For the newly created Input element, I´d need to define a Java Object matching it too.
For queries I´d end up with
Portfolio.java
@Entity
public class Portfolio {
@Id
private int id;
private String name;
....
}
and portfolio.graphqls
type Portfolio {
id: ID!
name: String
....
}
But for updates I´d end up with
Portfolio.java
@Entity
public class Portfolio {
@Id
private int id;
private String name;
....
}
PortfolioInput.java
@Entity
public class PortfolioInput {
@Id
private int id;
private String name;
....
}
portfolio.graphqls
type Portfolio {
id: ID!
name: String
....
}
input PortfolioInput {
id: ID!
name: String
....
}
type PortfolioMutation{
updatePortfolio(input: PortfolioInput):Portfolio
}
My problem with that is, I need to keep 4 entities in sync with their fields now, just because GraphQL does not allow using the type as input and I´d need to do that for many other entities as well.
Is there any other solution, or do people go the extra mile and accept the additional complexity, or do you simply switch to REST for POST/PUT operations and only use GraphQL for GET?