readGraphQlFilesWithCache method
read asset files with caching and hash-based validation Uses streaming processing for large files automatically
Implementation
Future<List<DocumentNode>> readGraphQlFilesWithCache(
BuildStep buildStep,
String schema,
) async {
// Compute current content hash
final currentHash = await _computeContentHash(buildStep, schema);
// Check if we have cached content and if hash matches
if (_fileCache.containsKey(schema) &&
_contentHashCache.containsKey(schema) &&
_contentHashCache[schema] == currentHash) {
return _fileCache[schema]!;
}
// Get asset IDs for the schema pattern
final assetIds = await buildStep.findAssets(Glob(schema)).toList();
// Always use regular parsing to preserve complete DocumentNode integrity.
// Streaming/chunked parsing splits large files into multiple documents,
// which breaks schema resolution (e.g., missing root types).
List<DocumentNode> documents;
if (assetIds.isNotEmpty) {
documents = await Future.wait(
assetIds.map(
(asset) async => parseString(
await buildStep.readAsString(asset),
url: asset.path,
),
),
);
} else {
documents = await readGraphQlFiles(buildStep, schema);
}
// Cache the results and hash
_fileCache[schema] = documents;
_contentHashCache[schema] = currentHash;
return documents;
}