Hi, everyone!
I'm interested in learning more about GraphQL with React Native and I've been playing around with AWS AppSync a little. I followed a basic tutorial but I want to build on that now and get my hands on. I have, however, hit a bit of a roadblock and I'd love some help.
The example I'm playing with is based on books. The requirements are:
I'm not sure how books and categories will be linked. Ideally, by ids of each, I guess.
Within the app itself, I'd like to be able to first show all categories and then, if a user taps on a category, they're taken to a page showing all books in that category. I've never used AppSync, GraphQL, or DynamoDB before so I'm a little lost how I should set up this relationship. I started with this:
type Query {
fetchBook(id: ID!): Book
fetchCategory(id: ID!: Category
}
type Book {
id: ID!
name: String!
author: String!
categories: [Category]!
}
type Category {
id: ID!
name: String!
books: [Book]
}
My idea was that a book might have many categories and a category could have many books. When I click Generate Resources in AppSync it creates everything but there's no sign of categories in the CreateBookInput nor books in CreateCategoryInput. Is this the right way to approach it? I wondered if it was also possible to just store an array of book ids (strings) with each category and then when doing the query for the books in a category, query against that list of ids. This, however, feels a bit too manual and I'm hoping there's a better way. Again, being new with this I'm not sure if that's possible. I'm still reading up on this all.
I know I'm missing something here, likely in the resolvers for creation, but I'm not sure what. I've been struggling with this for a while today so any help/advice would be very welcome!
Thanks!
No responses yet.