in doc-architect/doc-architect-core/src/main/java/com/docarchitect/core/scanner/impl/schema/GraphQLScanner.java [162:222]
public ScanResult scan(ScanContext context) {
log.info("Scanning GraphQL schemas in: {}", context.rootPath());
// Read configurable limits from context
long maxFileSizeBytes = getMaxFileSizeBytes(context);
int maxSchemaLines = getMaxSchemaLines(context);
log.debug("GraphQL scanner limits: maxFileSize={}MB, maxLines={}",
maxFileSizeBytes / 1_048_576, maxSchemaLines);
List<ApiEndpoint> apiEndpoints = new ArrayList<>();
List<DataEntity> dataEntities = new ArrayList<>();
// Find all GraphQL schema files
List<Path> schemaFiles = new ArrayList<>();
context.findFiles(GRAPHQL_FILE_PATTERN).forEach(schemaFiles::add);
context.findFiles(GQL_FILE_PATTERN).forEach(schemaFiles::add);
if (schemaFiles.isEmpty()) {
log.warn("No GraphQL schema files found in project");
return emptyResult();
}
List<String> warnings = new ArrayList<>();
for (Path schemaFile : schemaFiles) {
try {
// Pre-filter: Skip files that are too large to parse safely
if (!shouldScanFile(schemaFile, maxFileSizeBytes, maxSchemaLines, warnings)) {
continue;
}
// Performance logging
long startTime = System.currentTimeMillis();
parseSchemaFile(schemaFile, apiEndpoints, dataEntities);
long duration = System.currentTimeMillis() - startTime;
if (duration > 1000) {
log.info("Parsed large GraphQL schema: {} ({} ms)", schemaFile.getFileName(), duration);
} else {
log.debug("Parsed GraphQL schema: {} ({} ms)", schemaFile.getFileName(), duration);
}
} catch (Exception e) {
log.error("Failed to parse GraphQL schema: {}", schemaFile, e);
// Don't fail the entire scan - just skip this file and log a warning
warnings.add("Failed to parse GraphQL schema: " + schemaFile.getFileName() + " - " + e.getMessage());
}
}
log.info("Found {} GraphQL types and {} operations across {} schema files",
dataEntities.size(), apiEndpoints.size(), schemaFiles.size());
return buildSuccessResult(
List.of(), // No components
List.of(), // No dependencies
apiEndpoints,
List.of(), // No message flows
dataEntities,
List.of(), // No relationships
warnings
);
}