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

Eager load multiple nested relations using @with #2525

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Execution/ModelsLoader/SimpleModelsLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function __construct(

public function load(EloquentCollection $parents): void
{
$parents->load([$this->relation => $this->decorateBuilder]);
$parents->loadMissing([$this->relation => $this->decorateBuilder]);
}

public function extract(Model $model): mixed
Expand Down
1 change: 0 additions & 1 deletion src/Schema/Directives/WithDirective.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public function manipulateFieldDefinition(DocumentAST &$documentAST, FieldDefini
}
}

/** @return SimpleModelsLoader */
protected function modelsLoader(mixed $parent, array $args, GraphQLContext $context, ResolveInfo $resolveInfo): ModelsLoader
{
return new SimpleModelsLoader(
Expand Down
6 changes: 3 additions & 3 deletions src/Tracing/FederatedTracing/Proto/ContextualizedStats.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/Tracing/FederatedTracing/Proto/FieldStat.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Tracing/FederatedTracing/Proto/InputFieldStats.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Tracing/FederatedTracing/Proto/LimitsStats.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/Tracing/FederatedTracing/Proto/QueryLatencyStats.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions src/Tracing/FederatedTracing/Proto/Trace.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Tracing/FederatedTracing/Proto/Trace/Limits.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 9 additions & 16 deletions tests/Integration/Schema/Directives/WithDirectiveTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function testEagerLoadsNestedRelation(): void
{
$this->schema = /** @lang GraphQL */ '
type Query {
users: User @first
user: User @first
}

type User {
Expand Down Expand Up @@ -92,13 +92,13 @@ public function testEagerLoadsNestedRelation(): void

$this->graphQL(/** @lang GraphQL */ '
{
users {
user {
postsCommentsLoaded
}
}
')->assertJson([
'data' => [
'users' => [
'user' => [
'postsCommentsLoaded' => true,
],
],
Expand Down Expand Up @@ -247,8 +247,7 @@ public function testEagerLoadsMultipleRelationsAtOnce(): void
{
$this->schema = /** @lang GraphQL */ '
type Query {
users: User
@first
user: User @first
}

type User {
Expand Down Expand Up @@ -287,13 +286,13 @@ public function testEagerLoadsMultipleRelationsAtOnce(): void

$this->graphQL(/** @lang GraphQL */ '
{
users {
user {
tasksAndPostsCommentsLoaded
}
}
')->assertJson([
'data' => [
'users' => [
'user' => [
'tasksAndPostsCommentsLoaded' => true,
],
],
Expand All @@ -302,15 +301,9 @@ public function testEagerLoadsMultipleRelationsAtOnce(): void

public function testEagerLoadsMultipleNestedRelationsAtOnce(): void
{
$eloquentCollection = \Illuminate\Database\Eloquent\Collection::class;
$simpleModelsLoader = \Nuwave\Lighthouse\Execution\ModelsLoader\SimpleModelsLoader::class;
$this->markTestSkipped("Not working due to the current naive usage of {$eloquentCollection}::load() in {$simpleModelsLoader}::load().");

// @phpstan-ignore-next-line unreachable due to markTestSkipped
$this->schema = /** @lang GraphQL */ '
type Query {
users: User
@first
user: User @first
}

type User {
Expand Down Expand Up @@ -361,13 +354,13 @@ public function testEagerLoadsMultipleNestedRelationsAtOnce(): void

$this->graphQL(/** @lang GraphQL */ '
{
users {
user {
postTasksAndPostsCommentsLoaded
}
}
')->assertJson([
'data' => [
'users' => [
'user' => [
'postTasksAndPostsCommentsLoaded' => true,
],
],
Expand Down