Skip to content

Commit

Permalink
Add test for path + unaliasedpath in lists
Browse files Browse the repository at this point in the history
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)
````
  • Loading branch information
ruudk authored and spawnia committed Jun 19, 2024
1 parent 4ddba16 commit 5f77870
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions tests/Type/ResolveInfoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace GraphQL\Tests\Type;

use GraphQL\GraphQL;
use GraphQL\Type\Definition\ListOfType;
use GraphQL\Type\Definition\ObjectType;
use GraphQL\Type\Definition\ResolveInfo;
use GraphQL\Type\Definition\Type;
Expand Down Expand Up @@ -518,4 +519,81 @@ public function testPathAndUnaliasedPath(): void
],
], $result);
}

public function testPathAndUnaliasedPathForList(): void
{
$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);
},
],
'scalar2' => [
'type' => Type::string(),
'resolve' => static function ($value, array $args, $context, ResolveInfo $info) {
return 'path: ' . implode('.', $info->path) . ', unaliasedPath: ' . implode('.', $info->unaliasedPath);
},
],
],
]);
$level1 = new ObjectType([
'name' => 'level1',
'fields' => [
'level2' => [
'type' => ListOfType::listOf($level2),
'resolve' => function () {
return ['a', 'b', 'c'];
},
],
],
]);

$query = new ObjectType([
'name' => 'Query',
'fields' => [
'level1' => [
'type' => $level1,
'resolve' => function () {
return true;
},
],
],
]);

$result = GraphQL::executeQuery(
new Schema(['query' => $query]),
<<<GRAPHQL
query {
level1 {
level2 {
scalar1
}
level1000: level2 {
scalar2
}
}
}
GRAPHQL
)->toArray();

self::assertSame([
'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'],
],
'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'],
],
],
],
], $result);
}
}

0 comments on commit 5f77870

Please sign in to comment.