Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Denormalized Type composition #176

Closed
oojacoboo opened this issue Nov 12, 2019 · 2 comments
Closed

Denormalized Type composition #176

oojacoboo opened this issue Nov 12, 2019 · 2 comments

Comments

@oojacoboo
Copy link
Collaborator

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.

@moufmouf
Copy link
Member

Hey Jacob,

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.

See https://graphqlite.thecodingmachine.io/docs/next/inheritance-interfaces#mapping-interfaces

Does it answer your question?

@oojacoboo
Copy link
Collaborator Author

Maybe. Interfaces could help to some extent.

Assuming we're using some type of aggregation approach, how would this be handled with a GraphQL type? Do you have an example?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants