You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Apollo GraphQL报错:listing.getXX不是函数问题求助

我刚接触Express.js/React/Apollo/GraphQL技术栈,目前还处于摸索阶段。我以现有代码为蓝本新增功能(逻辑完全一致,仅名称和数据库表不同),且已仔细确认新代码和数据库表的实现与现有功能完全一致,但仍遇到以下报错:

Error: GraphQL error: listing.getTransportLinks is not a function
GraphQL error: listing.getInTheArea is not a function
at new ApolloError (D:\path\to\project\node_modules\apollo-client\src\errors\ApolloError.js:34:28)
at D:\path\to\project\node_modules\apollo-client\src\core\QueryManager.js:325:41
at D:\path\to\project\node_modules\apollo-client\src\core\QueryManager.js:818:25
at Array.forEach ()
at D:\path\to\project\node_modules\apollo-client\src\core\QueryManager.js:815:27
at Array.forEach ()
at QueryManager.broadcastQueries (D:\path\to\project\node_modules\apollo-client\src\core\QueryManager.js:812:42)
at D:\path\to\project\node_modules\apollo-client\src\core\QueryManager.js:747:31

但现有功能中,D:\path\to\project\src\data\types\ShowListingType.js里引用的getUserSafetyAmenities()方法并未在代码库中明确定义,示例代码如下:

const ShowListingType = new ObjectType({
  name: 'ShowListing',
  fields: {
    ...
    userSafetyAmenities: {
      type: new List(UserSafetyAmenities),
      resolve(listing) {
        return listing.getUserSafetyAmenities();
      }
    },
    ...
  }
});
export default ShowListingType;

我推测getUserSafetyAmenities()是动态生成的,但我已完全模仿SafetyAmenities的实现方式来开发TransportLinks和InTheArea,却无法解决报错,希望能得到排查或调试方向的提示。我的开发环境是Windows+VS Code。


更新说明

很抱歉,我犯了一个方法名称的错误——我反复检查了所有内容,却很久都没发现!我在调用getX方法时遗漏了"User"一词,正确的应该是getUserX。(其实原开发者选择的"User"关键字并不合理,但这无关紧要。由于已有他人贡献内容,Stack Overflow不允许我删除该问题,但我不确定这个疏忽类问题对他人是否有用。)

内容的提问来源于stack exchange,提问作者lm713

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.29 03:07:37