I have a database schema that has a one to many relationship. For e.g. one department has many customer. Is it possible to have a mutation that create a customer and a department and associate them? Or the correct way is to create a customer than a department and then associate each other?
In the second approach I need to make three trips instead of one. Can someone provide me a GraphQL handling this situation?
You can define your mutation input to support nested types. This will allow you to send both
Department
andCustomer
in a single mutation.In the return payload, you can specify in your query to return the newly created
Department
and it's associatedCustomer
.You will allow you to mutate and query for associated entities in one trip.
Things get a bit complex if you're using
Connections
to define the relationship, but the basic principle is the same.