API Requests WriteTuplesRequest - evansims/openfga-php GitHub Wiki

Request for writing and deleting relationship tuples in OpenFGA. This request enables batch creation and deletion of relationship tuples, supporting both transactional (all-or-nothing) and non-transactional (independent operations) modes. Transactional mode ensures atomic changes, while non-transactional mode allows for parallel processing with detailed success/failure tracking.

Table of Contents


Namespace

OpenFGA\Requests


Source

View source code


Implements


Related Classes


Methods

chunk

public function chunk(int $chunkSize): array<WriteTuplesRequest>

Split this request into smaller chunks for non-transactional processing.

View source


Parameters

Name Type Description
$chunkSize int Maximum tuples per chunk (1-100)

Returns

array&lt;[WriteTuplesRequest](WriteTuplesRequest)&gt; — Array of chunked requests


getDeletes

public function getDeletes(): ?OpenFGA\Models\Collections\TupleKeysInterface

Get the relationship tuples to delete from the store. Returns a collection of relationship tuples that should be removed from the authorization store. Each tuple represents a permission or relationship that will be revoked. The deletion is atomic with any write operations specified in the same request.

View source


Returns

TupleKeysInterface | null — Collection of relationship tuples to remove, or null if no deletions are requested


getMaxParallelRequests

public function getMaxParallelRequests(): int

Get the maximum number of parallel requests for non-transactional mode.

View source


Returns

int — Maximum parallel requests (1 for sequential processing)


getMaxRetries

public function getMaxRetries(): int

Get the maximum number of retries for failed chunks in non-transactional mode.

View source


Returns

int — Maximum retry attempts


getMaxTuplesPerChunk

public function getMaxTuplesPerChunk(): int

Get the maximum number of tuples per chunk for non-transactional mode.

View source


Returns

int — Maximum tuples per chunk (up to 100)


getModel

public function getModel(): string

Get the authorization model ID to use for tuple validation. Specifies which version of the authorization model should be used to validate the relationship tuples being written or deleted. This ensures that all tuples conform to the expected schema and relationship types defined in the model.

View source


Returns

string — The authorization model ID for validating tuple operations


getRequest

public function getRequest(Psr\Http\Message\StreamFactoryInterface $streamFactory): OpenFGA\Network\RequestContext

Build a request context for HTTP execution. Transforms the request object into a standardized HTTP request context that can be executed by the OpenFGA HTTP client. This method handles all aspects of request preparation including parameter serialization, URL construction, header configuration, and body stream creation. The method validates that all required parameters are present and properly formatted, serializes complex objects to JSON, constructs the appropriate API endpoint URL, and creates the necessary HTTP message body streams.

View source


Parameters

Name Type Description
$streamFactory StreamFactoryInterface PSR-7 stream factory for creating request body streams from serialized data

Returns

RequestContext — The prepared request context containing HTTP method, URL, headers, and body ready for execution


getRetryDelaySeconds

public function getRetryDelaySeconds(): float

Get the retry delay in seconds for non-transactional mode.

View source


Returns

float — Retry delay in seconds


getStopOnFirstError

public function getStopOnFirstError(): bool

Check if non-transactional processing should stop on first error.

View source


Returns

bool — True to stop on first error, false to continue


getStore

public function getStore(): string

Get the store ID where tuples will be written. Identifies the OpenFGA store that contains the authorization data to be modified. All write and delete operations will be performed within the context of this specific store.

View source


Returns

string — The store ID containing the authorization data to modify


getTotalOperations

public function getTotalOperations(): int

Get the total number of tuple operations in this request.

View source


Returns

int — Total count of write and delete operations


getWrites

public function getWrites(): ?OpenFGA\Models\Collections\TupleKeysInterface

Get the relationship tuples to write to the store. Returns a collection of relationship tuples that should be added to the authorization store. Each tuple represents a new permission or relationship that will be granted. The write operation is atomic with any delete operations specified in the same request.

View source


Returns

TupleKeysInterface | null — Collection of relationship tuples to add, or null if no writes are requested


isEmpty

public function isEmpty(): bool

Check if this request contains any operations.

View source


Returns

bool — True if the request has no operations


isTransactional

public function isTransactional(): bool

Check if this request should be executed in transactional mode.

View source


Returns

bool — True for transactional mode, false for non-transactional

⚠️ **GitHub.com Fallback** ⚠️