对于 AWS 放大中的模式,graphql 中的数组和映射是否有标量类型?

Shi*_*aaz 4 graphql aws-amplify

我正在学习将 AWS amplify 与 React 结合使用,它使用的 API 是一个利用 AWS AppSync 的 GraphQL API。我对 graphQL 很陌生,目前我的架构是这样的。这是放大应用程序内的架构:

type Note @model {
  id: ID!
  name: String!
  description: String
  title: String
  image: String
}
Run Code Online (Sandbox Code Playgroud)

举个例子,我想在 Note 类型的组件中存储一个对象数组,如下所示:

代码 1

type Note @model {
  id: ID!
  name: String!
  description: String
  title: String
  image: String
  components: []
}
Run Code Online (Sandbox Code Playgroud)

但是阅读文档我知道没有任何数组标量类型。我知道我可以创建另一个表并这样做:

代码 2

 type Note @model {
  id: ID!
  name: String!
  description: String
  title: String
  image: String
  components: [elements!]!
}
 
 type elements @model {
  id: ID!
  item: String!
}
Run Code Online (Sandbox Code Playgroud)

但我不想要这个,因为它会创建一个新表。我只想要一个包含 id、名称、描述、标题、图像和一个组件数组的表,您可以在其中存储对象,如上面Code-1 所示。有没有可能的方法来做到这一点?还有“@modal”在模式中的作用是什么?

Shi*_*aaz 5

查看了 AWS 文档,发现我可以将 AWSJSON 用于 [1, 2, 3] 之类的列表/数组和 {"upvotes": 10} 之类的映射,所以现在我的架构是:

type Note @model {
  id: ID!
  name: String!
  description: String
  title: String
  image: String
  components: AWSJSON
}
Run Code Online (Sandbox Code Playgroud)

这是了解更多信息的链接AWS 标量类型