GraphRequestManager class manages the execution of one or more Graph API requests, with support for batch processing and callbacks.
Import
Constructor
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.
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.
start
Executes all requests in the batch.number
Optional timeout in milliseconds. Defaults to 0 (no timeout).
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:- Reduced network overhead - Single HTTP request for multiple Graph API calls
- Lower latency - Parallel execution of independent requests
- Better resource usage - Fewer round trips to Facebook servers
- Cleaner code - Centralized completion handling
Best Practices
- Batch related requests together when possible
- Set appropriate timeouts for your network conditions
- Handle individual request errors in addition to batch errors
- Use batch callbacks for loading state management
- Limit batch size to avoid excessively long requests (Facebook recommends max 50 requests per batch)
- Check platform differences for network error handling
Related
- GraphRequest - Create individual Graph API requests
- Facebook Graph API Documentation
- React Native NetInfo - Network status detection