generateCacheKey method
Generates a deterministic cache key for a request.
The key is a SHA-256 hash of:
- Operation name
- Query document string
- JSON-encoded variables
This ensures that identical queries with identical variables produce the same cache key.
Implementation
String generateCacheKey(Request request) {
final operation = request.operation;
final queryString = operation.document.toString();
final variables = request.variables;
final operationName = operation.operationName ?? '';
// Create deterministic string representation
final keyComponents = [
operationName,
queryString,
jsonEncode(variables),
];
// Generate SHA-256 hash for compact, collision-resistant key
return sha256.convert(utf8.encode(keyComponents.join('|'))).toString();
}