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
Allow lazy root types (query, mutation, subscription) #1418
Conversation
This makes it possible to create a schema with the root types lazy. This way, only when the root type is needed, the type will be initialized by calling the callable. Why would a Schema have an instance of the mutation and subscription root type, when it's only serving a query operation? Visa versa. That does not make sense to me.
Nice concept. Don't know why I didn't think of it when I was working on this stuff. 👍 |
@spawnia nice, added some tweaks as comments |
Thank you, released with https://github.com/webonyx/graphql-php/releases/tag/v15.6.0. |
Very nice 🤘 |
Is it possible to leverage this lazy loading using the schema definition language? |
Sure, depends on the implementation. |
This makes it possible to create a schema with the root types lazy. This way, only when the root type is needed, the type will be initialized by calling the callable.
Why would a Schema have an instance of the mutation and subscription root type, when it's only serving a query operation? Visa versa. That does not make sense to me.
This is in line with the rest of the codebase, where all the types can be passed as lazy.
Alternative solution
An alternative solution could be to allow passing a string with the name of the root type. When needed, the Schema will call the typeLoader with the given name. For example: