joskfg / graphql-bulk-resolver
GraphQL Bulk Resolver
Installs: 1 311
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 1
Forks: 1
Open Issues: 0
Requires
- php: >=7.0
- webonyx/graphql-php: ^0.12
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.4
- infection/infection: ^0.8.1
- mockery/mockery: ^1.0
- phpstan/phpstan: ^0.9.2
- phpunit/phpunit: ^6.0
This package is auto-updated.
Last update: 2024-11-17 11:25:56 UTC
README
Trait to avoid N+1 problem in GraphQL when using the webonyx/graphql-php or any wrapper. It is based in the Deferred resolvers that provide the library and allow you to work with them in an easy way.
Documentation
The trait split the resolver in two parts, fetch and pluck.
Fetch
This part receive all the root objects in one array, so you can process all of them in one shoot and return all the data in the best way to be processed in the pluck.
Pluck
The method receives all the data processed and the root that is requesting the info, so it should search inside the data processed and return the specific data.
You must implement the resolver using the DeferredResolverInterface
and use the trait in the resolver type like this:
'resolve' => $this->deferredResolve(new MyResolver());
You can see an article about the package at https://medium.com/@JoseCardona/solving-graphql-n-1-in-php-92ed9161dd7b
Testing
joskfg/graphql-bulk-resolver
has a PHPUnit test suite and a coding style compliance test suite using PHP CS Fixer.
To run the tests, run the following command from the project folder.
$ docker-compose run test
To run interactively using PsySH:
$ docker-compose run psysh
License
The MIT license. Please see LICENSE for more information.