Hi, I'm looking for any advice on which path to take when structuring and hence, naming Queries. It basically comes down to whether the query models the intent of the screen or what it will ultimately return. The choice seems to subsequently have some structural implications. Note: This is example is all in a single Bounded Context.
Up until now, for simple screens, I've been returning a read model per screen (1 to 1 relationship) which is executed with a query handler. Say:
GetAllOrdersForCustomerQuery returns <list>OrderView
GetOrderDetailsQuery returns OrderDetailsView
These seem to follow most examples I've seen out there.
Imagine a more complicated case, say where an order is to be assigned to a specific delivery company from a list of those that deliver to the order's destination.
The screen supporting this needs the Order Details (and address), and also a list of the delivery companies supporting that address.
I can see two potential approaches:
- Stick to the current current style of CQRS pattern I'm using. The outcome of this appears to be that I will need to utilise two queries (and read models) for that screen:
GetOrderDetailsQuery returns OrderDetailsView
Then use the Query:
GetDeliveryCompaniesSupportingLocation returns <list>DeliveryCompanyView.
Basically breaking the screen up into subviews with each subview having it's own query.
- Continue to follow 1 read model per screen, in which naming of the query alters to follow the ultimate intent of the screen.
So:
GetAssignDeliveryCompanyToOrderQuery returns AssignDeliveryCompanyToOrderView (which contains the order details / address and a list of delivery companies).
For consistency it would then seem apt to rename my existing queries:
GetAllOrdersForCustomerQuery becomes GetSelectOrderForCustomerQuery
GetOrderDetailsQuery becomes GetDisplayOrderDetailsQuery
So seems to land on whether best practises call for
- A single query for a whole screen, or whether it's allowable in some scenarios to call multiple queries for a screen.
- Whether queries reflect that intent of the screen, or the type of information it will be returning.
Thanks