2017 © Pedro Peláez
 

library graphql-batch-processor

GraphQL batch processor

image

vasily-kartashov/graphql-batch-processor

GraphQL batch processor

  • Friday, June 29, 2018
  • by vasily-kartashov
  • Repository
  • 2 Watchers
  • 1 Stars
  • 705 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 42 % Grown

The README.md

GraphQL batch processor

Build Status, (*1)

Simple Example:

// Name of the cache is `addressesByUserId`
return Batch::as('addressesByUserId')
    // Collect user IDs
    ->collectOne($user->id())
    // When all user IDs are collected, fetch addresses for all collected user IDs
    // The callback is only executed once for each set of user IDs
    // And cached internally under the name `addressesByUserId`
    ->fetchOneToMany(function (array $userIds) { 
        return $this->addressRepository->findAddressesByUserIds($userIds);
    });

More complex example

return Batch::as('accountsByOrgranizationId')
    ->collectMultiple($organization->accountIds())
    ->fetchOneToOne(function (array $accountIds) {
        return $this->accountRepository->findAccountsByAccountIds($accountIds);
    });

Proper example

Get all addresses for each user; post filter out hidden addresses; format each address as a string; if there's no address, default to company's address, (*2)

return Batch::as('addressesByUserId')
    ->collectOne($user->id())
    ->filter(function (Address $address) {
        return !$address->hidden();
    })
    ->format(function (Address $address) {
        return (string) $address;
    })
    ->defaultTo([$company->defaultAddress()])
    ->fetchOneToMany(function (array $userIds) {
        return $this->addressRepository->findAddressesByUserIds($userIds);
    });

Tracing

Batches accept PSR-3 Loggers, (*3)

return Batch::as('usersByUserIds')
    ->setLogger($logger)
    ->collectOne(...)
    ...

The Versions

29/06 2018

dev-master

9999999-dev

GraphQL batch processor

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Vasily Kartashov

library batch graphql

06/02 2018

0.0.7

0.0.7.0

GraphQL batch processor

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Vasily Kartashov

library batch graphql

05/02 2018

0.0.6

0.0.6.0

GraphQL batch processor

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Vasily Kartashov

library batch graphql

31/01 2018

0.0.5

0.0.5.0

GraphQL batch processor

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Vasily Kartashov

library batch graphql