Skip to content

Commit

Permalink
Fix codegen log for unhandled array types
Browse files Browse the repository at this point in the history
  • Loading branch information
dafaqdhruv committed Apr 4, 2023
1 parent aa3c984 commit adf505d
Showing 1 changed file with 32 additions and 19 deletions.
51 changes: 32 additions & 19 deletions packages/codegen/src/visitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,30 +58,43 @@ export class Visitor {
return { name: item.name, type: item.typeName.name };
});

let errorMessage = '';

const typeName = node.returnParameters[0].typeName;
switch (typeName.type) {
case 'ElementaryTypeName': {
const returnType = typeName.name;

this._schema.addQuery(name, params, returnType);
this._resolvers.addQuery(name, params, returnType);
this._entity.addQuery(name, params, returnType);
this._database.addQuery(name, params, returnType);
this._client.addQuery(name, params, returnType);

// TODO Handle user defined type return.
if (typeName.type === 'UserDefinedTypeName') {
// Skip in case of UserDefinedTypeName.
return;
assert(this._contract);
this._indexer.addQuery(this._contract.name, MODE_ETH_CALL, name, params, returnType);

break;
}
case 'UserDefinedTypeName':
errorMessage = `No support in codegen for user defined return type from method "${node.name}"`;
break;

case 'ArrayTypeName':
errorMessage = `No support in codegen for return type "${typeName.baseTypeName.name}[]" from method "${node.name}"`;
break;

default:
errorMessage = `No support in codegen for return type "${typeName.type}" from method "${node.name}"`;
}

// TODO Handle multiple return parameters and array return type.
const returnType = typeName.name;
try {
this._schema.addQuery(name, params, returnType);
this._resolvers.addQuery(name, params, returnType);
this._entity.addQuery(name, params, returnType);
this._database.addQuery(name, params, returnType);
this._client.addQuery(name, params, returnType);

assert(this._contract);
this._indexer.addQuery(this._contract.name, MODE_ETH_CALL, name, params, returnType);
} catch (error: any) {
if (!this._continueOnError) {
throw error;
if (errorMessage !== '') {
if (this._continueOnError) {
console.log(errorMessage);
return;
}
console.log(error.message);

throw new Error(errorMessage);
}
}
}
Expand Down

0 comments on commit adf505d

Please sign in to comment.