You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So, this question is more related to the best way to approach this issue. I wasn't able to find a solid example in the docs.
I'd like to compose custom types that are built up from multiple model objects/collections. Often times we can handle the hydration/sql side with hydration to limit db queries, but I'm really not sure how it's best to structure something like this. It seems like what I want is a custom type object that uses the constructor for DI, or a Factory. The querying is handled in the controllers and then the controller would simply return this custom type.
I'm not sure if this is the best way to approach this though. How is it generally recommended to handle this? I assume everyone is simply returning their models 1:1 with GraphQL types.
The text was updated successfully, but these errors were encountered:
I assume everyone is simply returning their models 1:1 with GraphQL types.
Yes, I almost always map GraphQL types with my models.
Are you sure you want to have a custom type that aggregates several models / collections? Could you not fetch one object type and then fetch the others via aggregation?
Note that you could try to use interfaces (one interface per model) and build your custom type by creating a PHP class that implements the interfaces you want to aggregate. That way, each field declared in an interface would be available in the aggregated object.
So, this question is more related to the best way to approach this issue. I wasn't able to find a solid example in the docs.
I'd like to compose custom types that are built up from multiple model objects/collections. Often times we can handle the hydration/sql side with hydration to limit db queries, but I'm really not sure how it's best to structure something like this. It seems like what I want is a custom type object that uses the constructor for DI, or a Factory. The querying is handled in the controllers and then the controller would simply return this custom type.
I'm not sure if this is the best way to approach this though. How is it generally recommended to handle this? I assume everyone is simply returning their models 1:1 with GraphQL types.
The text was updated successfully, but these errors were encountered: