Skip to content

Commit

Permalink
Clarify ResolveInfoTest
Browse files Browse the repository at this point in the history
  • Loading branch information
spawnia committed Jun 19, 2024
1 parent 5f77870 commit dff1699
Showing 1 changed file with 96 additions and 44 deletions.
140 changes: 96 additions & 44 deletions tests/Type/ResolveInfoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -449,31 +449,35 @@ public function testDeepFieldSelectionOnDuplicatedFields(): void

public function testPathAndUnaliasedPath(): void
{
$resolveInfo = new ObjectType([
'name' => 'ResolveInfo',
'fields' => [
'path' => Type::listOf(Type::id()),
'unaliasedPath' => Type::listOf(Type::id()),
],
]);

$returnResolveInfo = static fn ($value, array $args, $context, ResolveInfo $info): ResolveInfo => $info;
$level2 = new ObjectType([
'name' => 'level2',
'fields' => [
'scalar1' => [
'type' => Type::string(),
'resolve' => static function ($value, array $args, $context, ResolveInfo $info) {
return 'path: ' . implode('.', $info->path) . ', unaliasedPath: ' . implode('.', $info->unaliasedPath);
},
'info1' => [
'type' => $resolveInfo,
'resolve' => $returnResolveInfo,
],
'scalar2' => [
'type' => Type::string(),
'resolve' => static function ($value, array $args, $context, ResolveInfo $info) {
return 'path: ' . implode('.', $info->path) . ', unaliasedPath: ' . implode('.', $info->unaliasedPath);
},
'info2' => [
'type' => $resolveInfo,
'resolve' => $returnResolveInfo,
],
],
]);

$level1 = new ObjectType([
'name' => 'level1',
'fields' => [
'level2' => [
'type' => $level2,
'resolve' => function () {
return true;
},
'resolve' => fn (): bool => true,
],
],
]);
Expand All @@ -483,9 +487,7 @@ public function testPathAndUnaliasedPath(): void
'fields' => [
'level1' => [
'type' => $level1,
'resolve' => function () {
return true;
},
'resolve' => fn (): bool => true,
],
],
]);
Expand All @@ -496,10 +498,16 @@ public function testPathAndUnaliasedPath(): void
query {
level1 {
level2 {
scalar1
info1 {
path
unaliasedPath
}
}
level1000: level2 {
scalar2
info2 {
path
unaliasedPath
}
}
}
}
Expand All @@ -510,10 +518,16 @@ public function testPathAndUnaliasedPath(): void
'data' => [
'level1' => [
'level2' => [
'scalar1' => 'path: level1.level2.scalar1, unaliasedPath: level1.level2.scalar1',
'info1' => [
'path' => ['level1', 'level2', 'info1'],
'unaliasedPath' => ['level1', 'level2', 'info1'],
],
],
'level1000' => [
'scalar2' => 'path: level1.level1000.scalar2, unaliasedPath: level1.level2.scalar2',
'info2' => [
'path' => ['level1', 'level1000', 'info2'],
'unaliasedPath' => ['level1', 'level2', 'info2'],
],
],
],
],
Expand All @@ -522,31 +536,35 @@ public function testPathAndUnaliasedPath(): void

public function testPathAndUnaliasedPathForList(): void
{
$resolveInfo = new ObjectType([
'name' => 'ResolveInfo',
'fields' => [
'path' => Type::listOf(Type::id()),
'unaliasedPath' => Type::listOf(Type::id()),
],
]);

$returnResolveInfo = static fn ($value, array $args, $context, ResolveInfo $info): ResolveInfo => $info;
$level2 = new ObjectType([
'name' => 'level2',
'fields' => [
'scalar1' => [
'type' => Type::string(),
'resolve' => static function ($value, array $args, $context, ResolveInfo $info) {
return 'path: ' . implode('.', $info->path) . ', unaliasedPath: ' . implode('.', $info->unaliasedPath);
},
'info1' => [
'type' => $resolveInfo,
'resolve' => $returnResolveInfo,
],
'scalar2' => [
'type' => Type::string(),
'resolve' => static function ($value, array $args, $context, ResolveInfo $info) {
return 'path: ' . implode('.', $info->path) . ', unaliasedPath: ' . implode('.', $info->unaliasedPath);
},
'info2' => [
'type' => $resolveInfo,
'resolve' => $returnResolveInfo,
],
],
]);

$level1 = new ObjectType([
'name' => 'level1',
'fields' => [
'level2' => [
'type' => ListOfType::listOf($level2),
'resolve' => function () {
return ['a', 'b', 'c'];
},
'resolve' => fn (): array => ['a', 'b', 'c'],
],
],
]);
Expand All @@ -556,9 +574,7 @@ public function testPathAndUnaliasedPathForList(): void
'fields' => [
'level1' => [
'type' => $level1,
'resolve' => function () {
return true;
},
'resolve' => fn (): bool => true,
],
],
]);
Expand All @@ -569,10 +585,16 @@ public function testPathAndUnaliasedPathForList(): void
query {
level1 {
level2 {
scalar1
info1 {
path
unaliasedPath
}
}
level1000: level2 {
scalar2
info2 {
path
unaliasedPath
}
}
}
}
Expand All @@ -583,14 +605,44 @@ public function testPathAndUnaliasedPathForList(): void
'data' => [
'level1' => [
'level2' => [
['scalar1' => 'path: level1.level2.0.scalar1, unaliasedPath: level1.level2.0.scalar1'],
['scalar1' => 'path: level1.level2.1.scalar1, unaliasedPath: level1.level2.1.scalar1'],
['scalar1' => 'path: level1.level2.2.scalar1, unaliasedPath: level1.level2.2.scalar1'],
[
'info1' => [
'path' => ['level1', 'level2', '0', 'info1'],
'unaliasedPath' => ['level1', 'level2', '0', 'info1'],
],
],
[
'info1' => [
'path' => ['level1', 'level2', '1', 'info1'],
'unaliasedPath' => ['level1', 'level2', '1', 'info1'],
],
],
[
'info1' => [
'path' => ['level1', 'level2', '2', 'info1'],
'unaliasedPath' => ['level1', 'level2', '2', 'info1'],
],
],
],
'level1000' => [
['scalar2' => 'path: level1.level1000.0.scalar2, unaliasedPath: level1.level2.0.scalar2'],
['scalar2' => 'path: level1.level1000.1.scalar2, unaliasedPath: level1.level2.1.scalar2'],
['scalar2' => 'path: level1.level1000.2.scalar2, unaliasedPath: level1.level2.2.scalar2'],
[
'info2' => [
'path' => ['level1', 'level1000', '0', 'info2'],
'unaliasedPath' => ['level1', 'level2', '0', 'info2'],
],
],
[
'info2' => [
'path' => ['level1', 'level1000', '1', 'info2'],
'unaliasedPath' => ['level1', 'level2', '1', 'info2'],
],
],
[
'info2' => [
'path' => ['level1', 'level1000', '2', 'info2'],
'unaliasedPath' => ['level1', 'level2', '2', 'info2'],
],
],
],
],
],
Expand Down

0 comments on commit dff1699

Please sign in to comment.