Skip to main content
The GraphRequestManager class manages the execution of one or more Graph API requests, with support for batch processing and callbacks.

Import

Constructor

Creates a new manager for executing Graph API requests.

Properties

requestBatch

Array of requests to be executed.

requestCallbacks

Array of callbacks corresponding to each request.

batchCallback

Optional callback invoked when the entire batch completes.

Methods

addRequest

Adds a Graph API request to the batch.
GraphRequest
required
The request to add to the batch.
Returns the manager instance for method chaining.

addBatchCallback

Sets a callback to be invoked when the entire batch finishes executing.
(error?, result?) => void
required
Function called when the batch completes. Only one batch callback can be set.
The batch callback indicates that execution has finished, not that every request succeeded. Check individual request callbacks for per-request status.
Returns the manager instance for method chaining.

start

Executes all requests in the batch.
number
Optional timeout in milliseconds. Defaults to 0 (no timeout).
Network error handling differs between platforms:
  • iOS: Batch callback returns an error if the batch fails due to network issues
  • Android: Batch callback always returns {"result": "batch finished executing"} after timeout, even with network errors
For network status detection on Android, use React Native’s NetInfo module instead.

Usage Examples

Single Request

Multiple Requests (Batch)

With Batch Callback

With Timeout

Complex Batch with Error Handling

Loading State Management

TypeScript Types

Callback

Record<string, unknown>
Error object if the operation failed, undefined otherwise.
Record<string, unknown>
Response data if the operation succeeded, undefined otherwise.

Method Chaining

All configuration methods return the manager instance, allowing fluent method chaining:

Performance Benefits

Batching multiple requests provides several benefits:
  1. Reduced network overhead - Single HTTP request for multiple Graph API calls
  2. Lower latency - Parallel execution of independent requests
  3. Better resource usage - Fewer round trips to Facebook servers
  4. Cleaner code - Centralized completion handling

Best Practices

  1. Batch related requests together when possible
  2. Set appropriate timeouts for your network conditions
  3. Handle individual request errors in addition to batch errors
  4. Use batch callbacks for loading state management
  5. Limit batch size to avoid excessively long requests (Facebook recommends max 50 requests per batch)
  6. Check platform differences for network error handling