Skip to content

Commit

Permalink
Add test to show that relations can be queried with conditions (#1560)
Browse files Browse the repository at this point in the history
Former-commit-id: 3a3e686
  • Loading branch information
spawnia authored Nov 27, 2020
1 parent d97c5af commit e201632
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
2 changes: 0 additions & 2 deletions src/Schema/Types/Scalars/Upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class Upload extends ScalarType
/**
* This always throws, as the Upload scalar can only be used as an argument.
*
*
* @throws \GraphQL\Error\InvariantViolation
*/
public function serialize($value): void
Expand All @@ -26,7 +25,6 @@ public function serialize($value): void
/**
* Parse a externally provided variable value into a Carbon instance.
*
*
* @throws \GraphQL\Error\Error
*/
public function parseValue($value): UploadedFile
Expand Down
44 changes: 41 additions & 3 deletions tests/Integration/Schema/Directives/HasManyDirectiveTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ protected function setUp(): void
parent::setUp();

$this->user = factory(User::class)->create();
$this->tasks = factory(Task::class, 3)->create([
'user_id' => $this->user->getKey(),
]);
$this->tasks = factory(Task::class, 3)->make();
$this->user->tasks()->saveMany($this->tasks);

factory(Task::class)->create([
'user_id' => $this->user->getKey(),
// This task should be ignored via global scope on the Task model
Expand Down Expand Up @@ -79,6 +79,44 @@ public function testCanQueryHasManyRelationship(): void
')->assertJsonCount(3, 'data.user.tasks');
}

public function testCanQueryHasManyWithCondition(): void
{
$this->schema = /** @lang GraphQL */ '
type User {
tasks(
id: ID @eq
): [Task!]! @hasMany
}
type Task {
id: Int
foo: String
}
type Query {
user: User @auth
}
';

/** @var Task $firstTask */
$firstTask = $this->user->tasks->first();

// Ensure global scopes are respected here
$this
->graphQL(/** @lang GraphQL */ '
query ($id: ID){
user {
tasks(id: $id) {
id
}
}
}
', [
'id' => $firstTask->id,
])
->assertJsonCount(1, 'data.user.tasks');
}

public function testCallsScopeWithResolverArgs(): void
{
$this->assertCount(3, $this->user->tasks);
Expand Down

0 comments on commit e201632

Please sign in to comment.