'Where to get resources to learn Designing Your Schema for dummies, I tried building my graphql schema using the new transformer v2 (fails)
I tried building my own schema but keep getting [Unhandled promise rejection: TypeError: undefined is not an object (evaluating 'post.save.items')]
I've been shuffling, changing my schema but it either gives me results I didn't want,lacks values I needed or just keeps failing. I am clearly not getting the hang of it. Is there any article that offers over-simplified explanation?
And in case anyone has got a second to spare, you can take a look at my schema and correct/explain what I am doing wrong. Cheers
My Schema
type User @model {
id: ID!
username: String
posts: [Post] @hasMany
}
type Post @model {
id: ID!
photo:String
userID: ID!
user: User @hasOne(fields: ["userID"])
saves: [Save]@hasMany(fields: ["id"])
}
type Save @model(queries: null) {
id: ID!
userID: ID!
postID: ID!
}
And then I edited my listPosts queries from:
export const listPosts = /* GraphQL */ `
query ListPosts {
listPosts {
items {
id
photo
userID
user {
id
username
}
saves {
nextToken
}
userPostsId
}
nextToken
}
}
`;
To:
export const listPosts = /* GraphQL */ `
query ListPosts {
listPosts {
items {
id
photo
userID
user {
id
username
}
saves {
items {
id
userID
postID
}
userPostsId
}
nextToken
}
}
`;
My initial intention was to have a user register with a simple username. Get presented with a list of posts(photos) and save any of them if they wanted to. A save would be made up of an object containing the save id,the user's id and the post id. If I query for listPosts all the photos are successfully relayed, but it lacks the save object and throws the error :[Unhandled promise rejection: TypeError: undefined is not an object (evaluating 'post.save.items')]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
