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

如何解决AWS GraphQL Schema Transformer v1转v2的Schema验证失败问题

修正后的Amplify GraphQL v2 Schema
type User @model {
  id: ID!
  username: String!
  email: String!
  imageUri: String
  posts: [Post] @hasMany(indexName: "byUser", fields: ["id"])
}

type Post @model @key(name: "byUser", fields: ["userID"]) {
  id: ID!
  videoUri: String!
  description: String!

  userID: ID!
  user: User @belongsTo(fields: ["userID"])

  songID: ID!
  song: Song @belongsTo(fields: ["songID"])
}

type Song @model {
  id: ID!
  name: String!
  imageUri: String
}

修正说明

  • Amplify GraphQL v2 废弃了旧版的@connection指令,改用@hasMany(一对多)、@belongsTo(多对一)这类语义化的关联指令。
  • 你遇到的错误是因为旧的@connection语法在v2中被解析时,自动生成的@index指令参数不兼容,替换为新的关联指令即可解决。
  • User中的posts字段用@hasMany关联Post,indexName对应原Schema中定义的byUser索引,fields指定关联的User主键id。
  • Post中的user和song字段用@belongsTo分别关联User和Song,通过fields指定对应的外键字段userID和songID。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.24 02:33:21