Open spawnia opened 3 years ago
Eloquent provides a method to load relations only when they are not loaded already loadMissing
. Could it be utilised here?
Unfortunately, changing https://github.com/nuwave/lighthouse/blob/4dd08990889ecf996a2a955434852c967cb9c2ee/src/Execution/ModelsLoader/SimpleModelsLoader.php#L29 to use loadMissing
causes many tests to fail - the underlying issue is that relations can be loaded multiple times in a single GraphQL query, but they may apply different conditions.
What problem does this feature proposal attempt to solve?
See https://github.com/nuwave/lighthouse/pull/1871. Database queries are unnecessarily duplicated.
Which possible solutions should be considered?
When using dot notation to batch load a relation, e.g.
@with(relation: "foo.bar.baz")
, we would have to pick apart the individual relation segments and resolve a batch loader for each one separately.Rough draft of how that might look:
Scopes and additional constraints only apply to the last relation query, so the intermediary queries can safely be batched together with other unconstrained queries on the same relation: