托管服务Subgraph按以太坊地址查询失败问题求助
解决Subgraph fulltext验证错误的方法
错误原因分析
- 类型不支持:
Bytes类型字段无法被fulltext索引,Graph的fulltext仅支持String、Int、BigInt、Boolean这类可文本化的类型,Bytes属于二进制类型,不满足全文索引的处理要求。 - 配置语法错误:fulltext的
fields数组写法有误,你将两个字段名写在了同一个对象中({ name: "userName", name: "_userAddress" }),每个字段必须是独立的对象;另外userName字段在你的User实体中不存在,属于无效字段。
修复步骤
1. 转换_userAddress字段类型
将_userAddress从Bytes改为String类型,因为你需要把它当作纯文本查询。修改User实体的schema:
type User @entity { id: ID! userId: BigInt! transactionHash: Bytes telephoneVerifiedData: String email: String # string _userAddress: String! # 替换Bytes为String类型 }
同时在映射代码(如AssemblyScript)中,把以太坊地址(Bytes类型)转成十六进制字符串存储,示例代码:
user._userAddress = event.params.userAddress.toHexString();
2. 修正fulltext配置
调整fields数组的写法,每个字段单独成对象,移除不存在的userName字段:
type _Schema_ @fulltext( name: "getUser" language: simple algorithm: rank include: [ { entity: "User", fields: [ { name: "_userAddress" }, { name: "email" } // 如果需要对email也做全文索引,可添加这行 ] } ] )
验证部署
完成上述修改后,重新生成Subgraph类型并执行部署操作,即可解决FulltextIncludedFieldInvalid("_userAddress")的验证错误。
内容的提问来源于stack exchange,提问作者Ahmed Dalhoum
相关产品推荐
相关产品推荐

