joskfg/graphql-bulk-resolver

GraphQL Bulk Resolver

0.4 2018-09-26 11:49 UTC

This package is auto-updated.

Last update: 2024-11-17 11:25:56 UTC


README

Latest Version Software License Build Status Coverage Status Quality Score Total Downloads

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.