Skip to content

Commit 5f77870

Browse files
ruudkspawnia
authored andcommitted
Add test for path + unaliasedpath in lists
This one fails on a525e5b: ``` 1) GraphQL\Tests\Type\ResolveInfoTest::testPathAndUnaliasedPathForList Failed asserting that two arrays are identical. --- Expected +++ Actual @@ @@ 'scalar1' => 'path: level1.level2.0.scalar1, unaliasedPath: level1.level2.0.scalar1', ], 1 => Array &5 [ - 'scalar1' => 'path: level1.level2.1.scalar1, unaliasedPath: level1.level2.1.scalar1', + 'scalar1' => 'path: level1.level2.1.scalar1, unaliasedPath: level1.level2.0.1.scalar1', ], 2 => Array &6 [ - 'scalar1' => 'path: level1.level2.2.scalar1, unaliasedPath: level1.level2.2.scalar1', + 'scalar1' => 'path: level1.level2.2.scalar1, unaliasedPath: level1.level2.0.1.2.scalar1', ], ], 'level1000' => Array &7 [ @@ @@ 'scalar2' => 'path: level1.level1000.0.scalar2, unaliasedPath: level1.level2.0.scalar2', ], 1 => Array &9 [ - 'scalar2' => 'path: level1.level1000.1.scalar2, unaliasedPath: level1.level2.1.scalar2', + 'scalar2' => 'path: level1.level1000.1.scalar2, unaliasedPath: level1.level2.0.1.scalar2', ], 2 => Array &10 [ - 'scalar2' => 'path: level1.level1000.2.scalar2, unaliasedPath: level1.level2.2.scalar2', + 'scalar2' => 'path: level1.level1000.2.scalar2, unaliasedPath: level1.level2.0.1.2.scalar2', ], ], ], ], ] ``` And succeeds on 4ddba16 ``` OK (1 test, 1 assertion) ````
1 parent 4ddba16 commit 5f77870

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

tests/Type/ResolveInfoTest.php

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace GraphQL\Tests\Type;
44

55
use GraphQL\GraphQL;
6+
use GraphQL\Type\Definition\ListOfType;
67
use GraphQL\Type\Definition\ObjectType;
78
use GraphQL\Type\Definition\ResolveInfo;
89
use GraphQL\Type\Definition\Type;
@@ -518,4 +519,81 @@ public function testPathAndUnaliasedPath(): void
518519
],
519520
], $result);
520521
}
522+
523+
public function testPathAndUnaliasedPathForList(): void
524+
{
525+
$level2 = new ObjectType([
526+
'name' => 'level2',
527+
'fields' => [
528+
'scalar1' => [
529+
'type' => Type::string(),
530+
'resolve' => static function ($value, array $args, $context, ResolveInfo $info) {
531+
return 'path: ' . implode('.', $info->path) . ', unaliasedPath: ' . implode('.', $info->unaliasedPath);
532+
},
533+
],
534+
'scalar2' => [
535+
'type' => Type::string(),
536+
'resolve' => static function ($value, array $args, $context, ResolveInfo $info) {
537+
return 'path: ' . implode('.', $info->path) . ', unaliasedPath: ' . implode('.', $info->unaliasedPath);
538+
},
539+
],
540+
],
541+
]);
542+
$level1 = new ObjectType([
543+
'name' => 'level1',
544+
'fields' => [
545+
'level2' => [
546+
'type' => ListOfType::listOf($level2),
547+
'resolve' => function () {
548+
return ['a', 'b', 'c'];
549+
},
550+
],
551+
],
552+
]);
553+
554+
$query = new ObjectType([
555+
'name' => 'Query',
556+
'fields' => [
557+
'level1' => [
558+
'type' => $level1,
559+
'resolve' => function () {
560+
return true;
561+
},
562+
],
563+
],
564+
]);
565+
566+
$result = GraphQL::executeQuery(
567+
new Schema(['query' => $query]),
568+
<<<GRAPHQL
569+
query {
570+
level1 {
571+
level2 {
572+
scalar1
573+
}
574+
level1000: level2 {
575+
scalar2
576+
}
577+
}
578+
}
579+
GRAPHQL
580+
)->toArray();
581+
582+
self::assertSame([
583+
'data' => [
584+
'level1' => [
585+
'level2' => [
586+
['scalar1' => 'path: level1.level2.0.scalar1, unaliasedPath: level1.level2.0.scalar1'],
587+
['scalar1' => 'path: level1.level2.1.scalar1, unaliasedPath: level1.level2.1.scalar1'],
588+
['scalar1' => 'path: level1.level2.2.scalar1, unaliasedPath: level1.level2.2.scalar1'],
589+
],
590+
'level1000' => [
591+
['scalar2' => 'path: level1.level1000.0.scalar2, unaliasedPath: level1.level2.0.scalar2'],
592+
['scalar2' => 'path: level1.level1000.1.scalar2, unaliasedPath: level1.level2.1.scalar2'],
593+
['scalar2' => 'path: level1.level1000.2.scalar2, unaliasedPath: level1.level2.2.scalar2'],
594+
],
595+
],
596+
],
597+
], $result);
598+
}
521599
}

0 commit comments

Comments
 (0)