Skip to content

Commit f401d0c

Browse files
committed
Fix subgraphs without abi field failing to build
1 parent f6079a6 commit f401d0c

File tree

1 file changed

+39
-19
lines changed

1 file changed

+39
-19
lines changed

packages/cli/src/compiler/index.ts

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,9 @@ export default class Compiler {
508508
`Failed to write compiled subgraph to ${displayDir}`,
509509
`Warnings while writing compiled subgraph to ${displayDir}`,
510510
async spinner => {
511+
// Add debug log for initial subgraph state
512+
compilerDebug('Initial subgraph state:', subgraph.toJS());
513+
511514
// Copy schema and update its path
512515
subgraph = subgraph.updateIn(['schema', 'file'], schemaFile => {
513516
const schemaFilePath = path.resolve(this.sourceDir, schemaFile as string);
@@ -518,32 +521,49 @@ export default class Compiler {
518521
return path.relative(this.options.outputDir, targetFile);
519522
});
520523

524+
// Add debug log before processing data sources
525+
compilerDebug('Processing dataSources:', subgraph.get('dataSources').toJS());
526+
521527
// Copy data source files and update their paths
522528
subgraph = subgraph.update('dataSources', (dataSources: any[]) =>
523529
dataSources.map(dataSource => {
530+
// Add debug log for each data source
531+
compilerDebug('Processing dataSource:', dataSource.toJS());
532+
524533
let updatedDataSource = dataSource;
525534

526535
if (this.protocol.hasABIs()) {
527-
updatedDataSource = updatedDataSource
528-
// Write data source ABIs to the output directory
529-
.updateIn(['mapping', 'abis'], (abis: any[]) =>
530-
abis.map((abi: any) =>
531-
abi.update('file', (abiFile: string) => {
532-
abiFile = path.resolve(this.sourceDir, abiFile);
533-
const abiData = this.ABI.load(abi.get('name'), abiFile);
534-
return path.relative(
535-
this.options.outputDir,
536-
this._writeSubgraphFile(
537-
abiFile,
538-
JSON.stringify(abiData.data.toJS(), null, 2),
539-
this.sourceDir,
540-
this.subgraphDir(this.options.outputDir, dataSource),
541-
spinner,
542-
),
543-
);
544-
}),
545-
),
536+
// Add debug log for ABIs
537+
compilerDebug(
538+
'Processing ABIs for dataSource:',
539+
dataSource.getIn(['mapping', 'abis'])?.toJS() || 'undefined',
540+
);
541+
542+
updatedDataSource = updatedDataSource.updateIn(['mapping', 'abis'], (abis: any[]) => {
543+
compilerDebug('ABIs value:', Array.isArray(abis) ? abis : 'undefined');
544+
545+
if (!abis) {
546+
compilerDebug('No ABIs found for dataSource');
547+
return immutable.List();
548+
}
549+
550+
return abis.map((abi: any) =>
551+
abi.update('file', (abiFile: string) => {
552+
abiFile = path.resolve(this.sourceDir, abiFile);
553+
const abiData = this.ABI.load(abi.get('name'), abiFile);
554+
return path.relative(
555+
this.options.outputDir,
556+
this._writeSubgraphFile(
557+
abiFile,
558+
JSON.stringify(abiData.data.toJS(), null, 2),
559+
this.sourceDir,
560+
this.subgraphDir(this.options.outputDir, dataSource),
561+
spinner,
562+
),
563+
);
564+
}),
546565
);
566+
});
547567
}
548568

549569
if (protocol.name == 'substreams' || protocol.name == 'substreams/triggers') {

0 commit comments

Comments
 (0)