-
-
Notifications
You must be signed in to change notification settings - Fork 567
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ResolveInfo::getFieldSelectionWithAliases() => now add instance types and the folded union types to the returned schema. #1681
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please fix the PHPStan issues, then mark as ready.
* } | ||
* } | ||
* | ||
* Given this ResolveInfo instance is a part of "root" field resolution, and $depth === 1, | ||
* Given this ResolveInfo instance is a part of "root" field resolution, $depth === 1, and nested represent an ObjectType with a configured name "Nested", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What exactly is meant by nested
here? A field?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I mean that the field described on line 233 represents an ObjectType with a property 'name' (or the result of the ->name() method) = "Nested".
I wrote this in order to emphasize the link between this field and the first ObjectType field in "myUnion" which contains the same field type.
It's probably not clear enough without the ObjectType + UnionType class config descriptions :/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Given this ResolveInfo instance is a part of "root" field resolution, $depth === 1, and nested represent an ObjectType with a configured name "Nested", | |
* Given this ResolveInfo instance is a part of root field resolution, | |
* $depth === 1, | |
* and fields "nested" represents an ObjectType named "Nested", |
src/Type/Definition/ResolveInfo.php
Outdated
* 'nested1' => [ | ||
* 'args' => [ | ||
* 'myArg' => 2, | ||
* 'mySecondAg' => "test, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks broken
src/Type/Definition/ResolveInfo.php
Outdated
* 'myUnion' => [ | ||
* 'myUnion' => [ | ||
* 'args' => [ | ||
* 'myArg' => 3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Always add trailing commas
src/Type/Definition/ResolveInfo.php
Outdated
* @throws \Exception | ||
* @return array<string, mixed> | ||
* | ||
* @throws Error | ||
* @throws InvariantViolation | ||
* | ||
* @return array<string, mixed> | ||
* | ||
* @throws \Exception |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I liked the previous order better
src/Type/Definition/ResolveInfo.php
Outdated
assert($parentType instanceof HasFieldsType, 'ensured by query validation'); | ||
|
||
$fieldDef = $parentType->getField($fieldName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing the assert
causes PHPStan failures.
tests/Type/ResolveInfoTest.php
Outdated
$result10 = GraphQL::executeQuery( | ||
new Schema(['query' => $query]), | ||
<<<GRAPHQL | ||
query { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
query { | |
{ |
$config = [ | ||
'fields' => [ | ||
'customA' => new MyCustomType(), | ||
'customB' => new OtherCustom(), | ||
], | ||
]; | ||
parent::__construct($config); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$config = [ | |
'fields' => [ | |
'customA' => new MyCustomType(), | |
'customB' => new OtherCustom(), | |
], | |
]; | |
parent::__construct($config); | |
parent::__construct([ | |
'fields' => [ | |
'customA' => new MyCustomType(), | |
'customB' => new OtherCustom(), | |
], | |
]); |
… and the folded union types to the returned schema.
Hi, thank you for the review. How should I fix this PHPStan error ?
On tests/Type/ResolveInfoTest.php Line 741 Something like this ?
|
I would do something like this: $fields = $myCustomWithObjectType->config['fields'];
assert(is_array($fields), 'ensured by type config');
$myCustomType = $fields['customA']; |
Hi,
After using the ResolveInfo::getFieldSelectionWithAliases() method I needed some additionnal data in order to go through the all schema properly.
So I have updated the method to add:
Before this update, we were able to go through union types but it was unreliable, some fields with the same name in different unioned types could be substituted for others.
Now it's consistent and it allows me in my application to handle a proper infinite level eager loading across the entire schema with unions.