Skip to content

Conversation

@ruudk
Copy link
Collaborator

@ruudk ruudk commented Aug 2, 2023

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.

$schema = new Schema([
    'query' => fn () => $query,
    'mutation' => fn () => $mutation,
    'subscription' => fn () => $subscription,
]);

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:

new Schema([
    'query' => 'Query',
    'typeLoader' => $typeLoader,
]);

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.
@ruudk ruudk force-pushed the lazy-root-types branch from b6267df to f4ca694 Compare August 2, 2023 17:58
@shmax
Copy link
Contributor

shmax commented Aug 2, 2023

Nice concept. Don't know why I didn't think of it when I was working on this stuff. 👍

@ruudk
Copy link
Collaborator Author

ruudk commented Aug 4, 2023

@spawnia nice, added some tweaks as comments

@spawnia spawnia merged commit 73ef849 into webonyx:master Aug 4, 2023
@spawnia
Copy link
Collaborator

spawnia commented Aug 4, 2023

@stayallive
Copy link
Contributor

Very nice 🤘

spawnia added a commit to nuwave/lighthouse that referenced this pull request Aug 7, 2023
@N-Silbernagel
Copy link

Is it possible to leverage this lazy loading using the schema definition language?

@spawnia
Copy link
Collaborator

spawnia commented Nov 28, 2023

Is it possible to leverage this lazy loading using the schema definition language?

Sure, depends on the implementation.

@ruudk ruudk deleted the lazy-root-types branch November 11, 2024 11:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants