You are here

public function BufferBase::createBufferResolver in GraphQL 8.4

Same name and namespace in other branches
  1. 8.3 src/GraphQL/Buffers/BufferBase.php \Drupal\graphql\GraphQL\Buffers\BufferBase::createBufferResolver()

Helper function to create a resolver for a singular buffer.

Parameters

object $item: The item to add to the buffer.

Return value

\Closure The callback to invoke to load the result for this buffer item.

3 calls to BufferBase::createBufferResolver()
EntityBuffer::add in src/GraphQL/Buffers/EntityBuffer.php
Add an item to the buffer.
EntityRevisionBuffer::add in src/GraphQL/Buffers/EntityRevisionBuffer.php
Add an item to the buffer.
EntityUuidBuffer::add in src/GraphQL/Buffers/EntityUuidBuffer.php
Add an item to the buffer.

File

src/GraphQL/Buffers/BufferBase.php, line 46

Class

BufferBase
Base class for field buffering services.

Namespace

Drupal\graphql\GraphQL\Buffers

Code

public function createBufferResolver($item) {
  $bufferId = $this
    ->getBufferId($item);
  if (!isset($this->buffers[$bufferId])) {
    $this->buffers[$bufferId] = new \SplObjectStorage();
  }
  if (!isset($this->results[$bufferId])) {
    $this->results[$bufferId] = new \SplObjectStorage();
  }

  // Add the created item to the buffer.
  $this->buffers[$bufferId]
    ->attach($item, $item);

  // Return a callback that can be used to resolve the buffer item.
  return $this
    ->createResolver($item, $this->buffers[$bufferId], $this->results[$bufferId]);
}