-
-
Notifications
You must be signed in to change notification settings - Fork 437
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
921981c
commit d1c8036
Showing
42 changed files
with
353 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Nuwave\Lighthouse\Schema\Directives; | ||
|
||
class HasOneThroughDirective extends RelationDirective | ||
{ | ||
public static function definition(): string | ||
{ | ||
return /** @lang GraphQL */ <<<'GRAPHQL' | ||
""" | ||
Corresponds to [the Eloquent relationship HasOneThrough](https://laravel.com/docs/eloquent-relationships#has-one-through). | ||
""" | ||
directive @hasOneThrough( | ||
""" | ||
Specify the relationship method name in the model class, | ||
if it is named different from the field in the schema. | ||
""" | ||
relation: String | ||
""" | ||
Apply scopes to the underlying query. | ||
""" | ||
scopes: [String!] | ||
) on FIELD_DEFINITION | ||
GRAPHQL; | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
tests/Integration/Schema/Directives/HasOneThroughDirectiveTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Tests\Integration\Schema\Directives; | ||
|
||
use Tests\DBTestCase; | ||
use Tests\Utils\Models\Post; | ||
use Tests\Utils\Models\PostStatus; | ||
|
||
final class HasOneThroughDirectiveTest extends DBTestCase | ||
{ | ||
public function testQueryHasOneThroughRelationship(): void | ||
{ | ||
$this->schema = /** @lang GraphQL */ ' | ||
type Query { | ||
tasks: [Task!]! @all | ||
} | ||
type Task { | ||
id: ID! | ||
postStatus: PostStatus @hasOneThrough | ||
} | ||
type PostStatus { | ||
id: ID! | ||
status: String | ||
} | ||
'; | ||
|
||
$post = factory(Post::class)->create(); | ||
assert($post instanceof Post); | ||
|
||
$postStatus = factory(PostStatus::class)->make(); | ||
assert($postStatus instanceof PostStatus); | ||
$postStatus->post()->associate($post); | ||
$postStatus->save(); | ||
|
||
$this->graphQL(/** @lang GraphQL */ ' | ||
{ | ||
tasks { | ||
id | ||
postStatus { | ||
id | ||
status | ||
} | ||
} | ||
} | ||
')->assertExactJson([ | ||
'data' => [ | ||
'tasks' => [ | ||
[ | ||
'id' => (string) $post->task->id, | ||
'postStatus' => [ | ||
'id' => (string) $postStatus->id, | ||
'status' => $postStatus->status, | ||
], | ||
], | ||
], | ||
], | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.