I’m working on exposing a set of GraphQL mutations for a simple domain model, which consists of the following entities:
Both, ModelA and ModelB have a reference to model Address which is stored at the end in the same table in our database:
Our team works to add simple mutations for ModelA and ModelB:
Our team thinks at the moment, that each mutation should always a fully separate input types, which means that input type for Addressshould not be shared between mutation for ModelA and mutation for ModelB.
Question: Can anyone advise if this is a correct approach – i.e. not sharing input for Address even though it’s the same entity in our database (?).
Either approach can work and there is no simple yes/no answer to your question. Both approaches have their tradeoffs so depending on your specific use case one might be preferred over the other, i.e.
shared input type - single type means that any update to the shared model impacts all your mutations (which might be the behavior that you want)
separate input types - you can have potentially duplicated models but since they are independent of each other you can change those inputs individually without affecting other mutations
Another question could be whether it makes sense to pass complex objects as inputs or update your mutations to accept multiple inputs (which is much simpler to evolve).
Side note: in general I’d advise against exposing your domain model directly in the graph and instead use GraphQL as an abstraction that would expose API that is driven by your client needs (a.k.a. “experience API”)