4
votes

I was learning to use AWS amplify with React, and the API it uses is a GraphQL API that leverages AWS AppSync. I'm very new to graphQL and my schema currently is like this. This is the schema inside the amplify app:

type Note @model {
  id: ID!
  name: String!
  description: String
  title: String
  image: String
}

To give you an example, I want to store an array of objects inside components in the Note type like this:

Code-1

type Note @model {
  id: ID!
  name: String!
  description: String
  title: String
  image: String
  components: []
}

But reading the docs I got to know there aren't any array scalar types. I know that I can create another table and do it like this instead:

Code-2

 type Note @model {
  id: ID!
  name: String!
  description: String
  title: String
  image: String
  components: [elements!]!
}
 
 type elements @model {
  id: ID!
  item: String!
}

But I don't want this as it creates a new table. I just want one table containing id, name, description, title, image and a components array where you can store objects in like shown above in Code-1. Is there any possible way to do this? Also whats the role of "@modal" in the schema?

1
"custom JSON scalar" - check general graphql and amplify docsxadm
@xadm Thank you so much. Figured out "AWSJSON" can be used, I guess my mistake was looking at the graphql docs instead of the AWS docs.Shiraaz

1 Answers

5
votes

Checked out the AWS docs and found out that I could use AWSJSON for lists/arrays like [1, 2, 3] and maps like {"upvotes": 10}, so now my schema is:

type Note @model {
  id: ID!
  name: String!
  description: String
  title: String
  image: String
  components: AWSJSON
}

Here is the link to know more about it AWS Scalar Types