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

AWS Amplify部署GraphQL多对多Schema报Expected Name, found @错误如何解决

问题原因

你遇到的报错是典型的GraphQL Schema语法括号不闭合导致的,具体错误点有两个:

  • 第一个@key指令的参数括号未闭合,你写的@key(name: "byUser", fields: ["userID", "communityID"]末尾缺少右括号)
  • 第二个@key指令的参数括号同样未闭合,你写的@key(name: "byCommunity", fields: ["communityID","userID"]末尾缺少右括号),直接接了类型定义的大括号{,导致解析器识别语法失败,抛出对应报错。

修正后的完整代码

type UserCommunity
  @auth
  @model(queries: null)
  @key(name: "byUser", fields: ["userID", "communityID"])
  @key(name: "byCommunity", fields: ["communityID","userID"]) {
  id: ID!
  userID: ID!
  communityID: ID!
  user: User! @connection(fields: ["userID"])
  community: Community! @connection(fields: ["communityID"])
}

修正后重新部署即可解决该语法报错。

内容的提问来源于stack exchange,提问作者Thomas S.

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.29 11:06:08