Skip to content

Create field args mapper and cache args resolution #1587

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

Merged
merged 37 commits into from
Oct 24, 2024

Conversation

Warxcell
Copy link
Contributor

@Warxcell Warxcell commented Jul 21, 2024

Small enhancement/performance optimization + new feature.

We already have input parse value which turns array into something user defined, but same thing for field args' is missing.

And because this could be something expensive (for example - user might validate if args are within defined boundaries) - it doesn't make sense to call that mapper (or even the code that collects the args) more than once for same input. (For example in sub fields of iterable - args won't change in between each iterable).

Did brief test on performance optimization - it was about 15ms on ~800 calls - not something big, but I believe its good to have it - it will be beneficial even to users that doesn't use that args mapper.

@spawnia spawnia changed the title Create field args mapper && cache args resolution Create field args mapper and cache args resolution Jul 22, 2024
@Warxcell
Copy link
Contributor Author

Any idea why phpstan could be falling? I can't run it locally to test, because for some reason it requires php8.2 and I have php8.3 locally.

@spawnia
Copy link
Collaborator

spawnia commented Jul 22, 2024

Any idea why phpstan could be falling? I can't run it locally to test, because for some reason it requires php8.2 and I have php8.3 locally.

Can you not see the output in https://github.com/webonyx/graphql-php/actions/runs/10038021756/job/27739070572?pr=1587?

Error: Method GraphQL\Tests\Executor\ResolveTest::buildSchema() has parameter $testField with no value type specified in iterable type array<string, mixed>.
Error: PHPDoc tag @param for parameter $testField contains unresolvable type.

GitHub also inlines the errors for me:

image

@Warxcell
Copy link
Contributor Author

Warxcell commented Jul 22, 2024

Any idea why phpstan could be falling? I can't run it locally to test, because for some reason it requires php8.2 and I have php8.3 locally.

Can you not see the output in https://github.com/webonyx/graphql-php/actions/runs/10038021756/job/27739070572?pr=1587?

Error: Method GraphQL\Tests\Executor\ResolveTest::buildSchema() has parameter $testField with no value type specified in iterable type array<string, mixed>.
Error: PHPDoc tag @param for parameter $testField contains unresolvable type.

GitHub also inlines the errors for me:

image

I see it, just don't understand it.
Type of param is specified, why it's say it isn't?

And why same code passes check with php7.4 & 8.0 but fails with 8.1, 8.2 & 8.3?

@Warxcell
Copy link
Contributor Author

Locally:

 php -dmemory_limit=-1 ./vendor/bin/phpstan
Note: Using configuration file /home/bozhidar_hristov/projects/graphql-php/phpstan.neon.dist.
 414/414 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%


                                                                                                                        
 [OK] No errors                                                                                                         
                                                                                                                        

🤷

@spawnia
Copy link
Collaborator

spawnia commented Oct 19, 2024

@Warxcell Please merge the latest changes from master, let's see if tests and static analysis pass.

@Warxcell
Copy link
Contributor Author

Done. No idea why phpstan is failing:
Locally I have this error (which again, no idea why happens)

------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
  Line   src/Utils/SchemaExtender.php                                                                                                                                                                                                                                             
 ------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
  424    Method GraphQL\Utils\SchemaExtender::extendImplementedInterfaces() should return array<int, GraphQL\Type\Definition\InterfaceType> but returns array<int, GraphQL\Type\Definition\InterfaceType|(GraphQL\Type\Definition\NamedType&T of GraphQL\Type\Definition\Type)>.  
 ------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 


                                                                                                                        
 [ERROR] Found 1 error                                                                                                  
                                               

@Warxcell Warxcell requested a review from spawnia October 23, 2024 11:04
@Warxcell Warxcell marked this pull request as draft October 23, 2024 12:11
@Warxcell
Copy link
Contributor Author

Warxcell commented Oct 23, 2024

Making draft, as I might seen a bug.

EDIT: It's fine - my fault on how I use it.

@Warxcell Warxcell marked this pull request as ready for review October 23, 2024 12:15
@spawnia
Copy link
Collaborator

spawnia commented Oct 23, 2024

@Warxcell
Copy link
Contributor Author

Warxcell commented Oct 23, 2024

I'm thinking something - maybe its better to use both $fieldDef and $fieldNode as cache key. So if

field {
   field2 <- if this is from interface, and it returns two versions of that interface - it would be called twice.
} 

It would be better I believe. Done.

@Warxcell Warxcell requested a review from spawnia October 23, 2024 13:04
@Warxcell Warxcell requested a review from spawnia October 24, 2024 07:26
@spawnia
Copy link
Collaborator

spawnia commented Oct 24, 2024

Thank your @Warxcell for your hard work and persistence on this!

@spawnia spawnia merged commit 9563fc5 into webonyx:master Oct 24, 2024
@spawnia
Copy link
Collaborator

spawnia commented Oct 24, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants