diff --git a/packages/codegen/src/visitor.ts b/packages/codegen/src/visitor.ts index 4db3f740f..cd595b415 100644 --- a/packages/codegen/src/visitor.ts +++ b/packages/codegen/src/visitor.ts @@ -59,30 +59,39 @@ export class Visitor { }); const typeName = node.returnParameters[0].typeName; + switch (typeName.type) { + case 'UserDefinedTypeName': { + const errorMessage = `No support in codegen for object of user defined type from method "${node.name}"`; + if (this._continueOnError) { + console.log(errorMessage); + return; + } + throw new Error(errorMessage); + } + + case 'ArrayTypeName': { + const errorMessage = `No support in codegen for object of type "${typeName.baseTypeName.name}[]" from method "${node.name}"`; - // TODO Handle user defined type return. - if (typeName.type === 'UserDefinedTypeName') { - // Skip in case of UserDefinedTypeName. - return; + if (this._continueOnError) { + console.log(errorMessage); + return; + } + + throw new Error(errorMessage); + } } // 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; - } - console.log(error.message); - } + + 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); } }