Skip to content

Commit d909fb2

Browse files
committed
Apply fixes from tooling updates
1 parent 8b3071f commit d909fb2

19 files changed

Lines changed: 112 additions & 120 deletions

src/LighthouseServiceProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public function register(): void
9595
));
9696

9797
$this->app->bind(ProvidesResolver::class, ResolverProvider::class);
98-
$this->app->bind(ProvidesSubscriptionResolver::class, static fn (): ProvidesSubscriptionResolver => new class() implements ProvidesSubscriptionResolver {
98+
$this->app->bind(ProvidesSubscriptionResolver::class, static fn (): ProvidesSubscriptionResolver => new class implements ProvidesSubscriptionResolver {
9999
public function provideSubscriptionResolver(FieldValue $fieldValue): \Closure
100100
{
101101
throw new \Exception('Register the SubscriptionServiceProvider to enable subscriptions.');

tests/Integration/Execution/DataLoader/PaginatedRelationLoaderTest.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,19 @@ static function (): void {},
3737
))->load($users);
3838

3939
$firstUser = $users[0];
40-
\PHPUnit\Framework\Assert::assertInstanceOf(User::class, $firstUser);
40+
$this->assertInstanceOf(User::class, $firstUser);
4141
$tasksPaginator = $firstUser->tasks;
42-
\PHPUnit\Framework\Assert::assertInstanceOf(LengthAwarePaginator::class, $tasksPaginator);
42+
$this->assertInstanceOf(LengthAwarePaginator::class, $tasksPaginator);
4343
$this->assertCount($pageSize, $tasksPaginator);
4444
$firstTask = $tasksPaginator[0];
45-
\PHPUnit\Framework\Assert::assertInstanceOf(Task::class, $firstTask);
45+
$this->assertInstanceOf(Task::class, $firstTask);
4646
$this->assertEquals($firstUser->getKey(), $firstTask->user_id);
4747

4848
$secondUser = $users[1];
49-
\PHPUnit\Framework\Assert::assertInstanceOf(User::class, $secondUser);
49+
$this->assertInstanceOf(User::class, $secondUser);
5050
$this->assertCount(2, $secondUser->tasks);
5151
$secondTask = $secondUser->tasks[0];
52-
\PHPUnit\Framework\Assert::assertInstanceOf(Task::class, $secondTask);
52+
$this->assertInstanceOf(Task::class, $secondTask);
5353
$this->assertEquals($secondUser->getKey(), $secondTask->user_id);
5454
}
5555

@@ -78,11 +78,11 @@ static function (): void {},
7878
))->load($users);
7979

8080
$firstUser = $users[0];
81-
\PHPUnit\Framework\Assert::assertInstanceOf(User::class, $firstUser);
81+
$this->assertInstanceOf(User::class, $firstUser);
8282
$this->assertSame($firstTasksCount, $firstUser->getAttributes()['tasks_count'] ?? null);
8383

8484
$secondUser = $users[1];
85-
\PHPUnit\Framework\Assert::assertInstanceOf(User::class, $secondUser);
85+
$this->assertInstanceOf(User::class, $secondUser);
8686
$this->assertSame($secondTasksCount, $secondUser->getAttributes()['tasks_count'] ?? null);
8787
}
8888

@@ -113,7 +113,7 @@ static function (): void {},
113113
))->load($users);
114114

115115
$firstUser = $users[0];
116-
\PHPUnit\Framework\Assert::assertInstanceOf(User::class, $firstUser);
116+
$this->assertInstanceOf(User::class, $firstUser);
117117

118118
$this->assertTrue($firstUser->relationLoaded('tasks'));
119119
$this->assertTrue($firstUser->relationLoaded('posts'));
@@ -154,12 +154,12 @@ static function (): void {},
154154
))->load($users);
155155

156156
$firstUser = $users[0];
157-
\PHPUnit\Framework\Assert::assertInstanceOf(User::class, $firstUser);
157+
$this->assertInstanceOf(User::class, $firstUser);
158158
$this->assertTrue($firstUser->relationLoaded('tasks'));
159159
$this->assertCount($tasksUser1, $firstUser->tasks);
160160

161161
$secondUser = $users[1];
162-
\PHPUnit\Framework\Assert::assertInstanceOf(User::class, $secondUser);
162+
$this->assertInstanceOf(User::class, $secondUser);
163163
$this->assertTrue($secondUser->relationLoaded('tasks'));
164164
$this->assertCount($tasksUser2, $secondUser->tasks);
165165
}
@@ -185,7 +185,7 @@ static function (): void {},
185185
))->load($tasks);
186186

187187
$firstTask = $tasks[0];
188-
\PHPUnit\Framework\Assert::assertInstanceOf(Task::class, $firstTask);
188+
$this->assertInstanceOf(Task::class, $firstTask);
189189
$this->assertCount($first, $firstTask->tags);
190190
}
191191

tests/Integration/Schema/Directives/AggregateDirectiveTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public function testSumRelationEagerLoad(): void
106106
->create()
107107
->each(static function (User $user, int $index): void {
108108
$task = factory(Task::class)->make();
109-
\PHPUnit\Framework\Assert::assertInstanceOf(Task::class, $task);
109+
self::assertInstanceOf(Task::class, $task);
110110
$task->difficulty = $index;
111111
$task->user()->associate($user);
112112
$task->save();

tests/Integration/Schema/Directives/HasManyDirectiveTest.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Tests\Integration\Schema\Directives;
44

5+
use Illuminate\Support\Arr;
6+
use Nuwave\Lighthouse\Exceptions\DefinitionException;
57
use Nuwave\Lighthouse\Pagination\PaginationArgs;
68
use PHPUnit\Framework\Attributes\DataProvider;
79
use Tests\DBTestCase;
@@ -1384,4 +1386,64 @@ public static function batchloadRelations(): iterable
13841386
yield [true];
13851387
yield [false];
13861388
}
1389+
1390+
public function testUsesEdgeTypeForRelayConnections(): void
1391+
{
1392+
$this->schema = /** @lang GraphQL */ <<<'GRAPHQL'
1393+
type User {
1394+
tasks: [Task!]! @hasMany (
1395+
type: CONNECTION
1396+
edgeType: "TaskEdge"
1397+
)
1398+
}
1399+
1400+
type Task {
1401+
id: Int
1402+
foo: String
1403+
}
1404+
1405+
type TaskEdge {
1406+
cursor: String!
1407+
node: Task!
1408+
}
1409+
1410+
type Query {
1411+
user: User @auth
1412+
}
1413+
GRAPHQL;
1414+
1415+
$expectedConnectionName = 'TaskEdgeConnection';
1416+
1417+
$this->assertNotEmpty(
1418+
$this->introspectType($expectedConnectionName),
1419+
);
1420+
1421+
$user = $this->introspectType('User');
1422+
$this->assertNotNull($user);
1423+
1424+
/** @var array<string, mixed> $user */
1425+
$tasks = Arr::first(
1426+
$user['fields'],
1427+
static fn (array $field): bool => $field['name'] === 'tasks',
1428+
);
1429+
$this->assertSame(
1430+
$expectedConnectionName,
1431+
$tasks['type']['ofType']['name'] ?? 0,
1432+
);
1433+
}
1434+
1435+
public function testThrowsErrorWithUnknownTypeArg(): void
1436+
{
1437+
$this->expectExceptionObject(new DefinitionException('Found invalid pagination type: foo'));
1438+
1439+
$this->buildSchemaWithPlaceholderQuery(/** @lang GraphQL */ <<<'GRAPHQL'
1440+
type User {
1441+
tasks(first: Int! after: Int): [Task!]! @hasMany(type: "foo")
1442+
}
1443+
1444+
type Task {
1445+
foo: String
1446+
}
1447+
GRAPHQL);
1448+
}
13871449
}

tests/Integration/Schema/Directives/MorphToManyDirectiveTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ public function testResolveMorphToManyUsingInterfaces(): void
213213
});
214214

215215
$task = factory(Task::class)->make();
216-
\PHPUnit\Framework\Assert::assertInstanceOf(Task::class, $task);
216+
$this->assertInstanceOf(Task::class, $task);
217217
$task->user()->associate($user);
218218
$task->save();
219219

tests/TestsSerialization.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ trait TestsSerialization
1414
{
1515
protected function fakeContextSerializer(): void
1616
{
17-
$contextSerializer = new class() implements SerializesContext {
17+
$contextSerializer = new class implements SerializesContext {
1818
public function serialize(GraphQLContext $context): string
1919
{
2020
return 'foo';
2121
}
2222

2323
public function unserialize(string $context): GraphQLContext
2424
{
25-
return new class() implements GraphQLContext {
25+
return new class implements GraphQLContext {
2626
public function user(): User
2727
{
2828
return new User();

tests/Unit/Auth/CanResolvedDirectiveTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function testChecksAgainstObject(): void
7878
$user->name = UserPolicy::ADMIN;
7979
$this->be($user);
8080

81-
$return = new class() {
81+
$return = new class {
8282
public string $name = 'foo';
8383
};
8484
$this->mockResolver(static fn (): object => $return);

tests/Unit/Auth/CanRootDirectiveTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public function testChecksAgainstObject(): void
103103
$user->name = UserPolicy::ADMIN;
104104
$this->be($user);
105105

106-
$return = new class() {
106+
$return = new class {
107107
public string $name = 'foo';
108108
};
109109
$this->mockResolver(static fn (): object => $return);

tests/Unit/Execution/CreatesContextTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ protected function getEnvironmentSetUp($app): void
1414
{
1515
parent::getEnvironmentSetUp($app);
1616

17-
$app->singleton(CreatesContext::class, static fn (): CreatesContext => new class() implements CreatesContext {
17+
$app->singleton(CreatesContext::class, static fn (): CreatesContext => new class implements CreatesContext {
1818
public function generate(?Request $request): GraphQLContext
1919
{
2020
return new FooContext();
@@ -25,7 +25,7 @@ public function generate(?Request $request): GraphQLContext
2525
public function testGenerateCustomContext(): void
2626
{
2727
$this->mockResolver(static function (mixed $root, array $args, GraphQLContext $context): string {
28-
\PHPUnit\Framework\Assert::assertInstanceOf(FooContext::class, $context);
28+
self::assertInstanceOf(FooContext::class, $context);
2929

3030
return $context->foo();
3131
});

tests/Unit/Execution/ResolveInfoTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ final class ResolveInfoTest extends TestCase
1717
{
1818
public function testApplyArgBuilderDirectives(): void
1919
{
20-
$directiveOne = new class() implements Directive, ArgBuilderDirective {
20+
$directiveOne = new class implements Directive, ArgBuilderDirective {
2121
public static function definition(): string
2222
{
2323
return '';
@@ -28,7 +28,7 @@ public function handleBuilder(QueryBuilder|EloquentBuilder|Relation $builder, mi
2828
return $builder->where('one', $value);
2929
}
3030
};
31-
$directiveTwo = new class() implements Directive, ArgBuilderDirective {
31+
$directiveTwo = new class implements Directive, ArgBuilderDirective {
3232
public static function definition(): string
3333
{
3434
return '';
@@ -39,7 +39,7 @@ public function handleBuilder(QueryBuilder|EloquentBuilder|Relation $builder, mi
3939
return $builder->where('two', $value);
4040
}
4141
};
42-
$directiveNested = new class() implements Directive, ArgBuilderDirective {
42+
$directiveNested = new class implements Directive, ArgBuilderDirective {
4343
public static function definition(): string
4444
{
4545
return '';
@@ -50,7 +50,7 @@ public function handleBuilder(QueryBuilder|EloquentBuilder|Relation $builder, mi
5050
return $builder->where('nested', $value);
5151
}
5252
};
53-
$directiveIgnored = new class() implements Directive, ArgBuilderDirective {
53+
$directiveIgnored = new class implements Directive, ArgBuilderDirective {
5454
public static function definition(): string
5555
{
5656
return '';
@@ -61,7 +61,7 @@ public function handleBuilder(QueryBuilder|EloquentBuilder|Relation $builder, mi
6161
return $builder->where('ignored', $value);
6262
}
6363
};
64-
$directiveWithoutInterface = new class() implements Directive {
64+
$directiveWithoutInterface = new class implements Directive {
6565
public static function definition(): string
6666
{
6767
return '';
@@ -95,7 +95,7 @@ public static function definition(): string
9595
$argumentSet->arguments['b'] = $argumentB;
9696

9797
$builder = User::query();
98-
$resolveInfo = new class() extends ResolveInfo {
98+
$resolveInfo = new class extends ResolveInfo {
9999
/** @phpstan-ignore-next-line no need to call parent `__construct` */
100100
public function __construct()
101101
{

0 commit comments

Comments
 (0)