Skip to content

Instantly share code, notes, and snippets.

@youneshenniwrites
Created December 13, 2018 14:38
Show Gist options
  • Save youneshenniwrites/891dbbcff96c8737aaa5277f30472169 to your computer and use it in GitHub Desktop.
Save youneshenniwrites/891dbbcff96c8737aaa5277f30472169 to your computer and use it in GitHub Desktop.
mutations and queries to perform CRUD operations to AWS DynamoDB
// Get all posts with all their likes
export const listPosts = `
query {
listPosts{
items {
id
postOwnerUsername
postContent
postOwnerId
likes {
items {
id
numberLikes
likeOwnerUsername
likeOwnerId
}
}
}
}
}
`
// Get a post and all its likes
export const getPost = `query($id:ID!) {
getPost(id:$id) {
id
postOwnerUsername
postContent
postOwnerId
likes {
items {
id
numberLikes
likeOwnerUsername
likeOwnerId
}
}
}
}`
// Create a post
export const createPost = `
mutation(
$postContent: String!,
$postOwnerId: String!,
$postOwnerUsername: String!
) {
createPost(input:{
postOwnerUsername: $postOwnerUsername,
postOwnerId: $postOwnerId,
postContent: $postContent
}) {
id
}
}
`
// Delete a post
export const deletePost = `
mutation($id:ID!) {
deletePost(input:{
id: $id,
}) {
id
}
}
`
// Create a like for a post
export const createLike = `
mutation (
$id:ID!,
$numberLikes: Int!,
$likeOwnerUsername: String!,
$likeOwnerId: String!
) {
createLike(input:{
likePostId: $id,
numberLikes:$numberLikes,
likeOwnerId: $likeOwnerId,
likeOwnerUsername: $likeOwnerUsername
}) {
id
numberLikes
post {
id
postContent
}
}
}
`
// Delete a like
export const deleteLike = `
mutation($id:ID!) {
deleteLike(input:{
id: $id,
}) {
id
}
}
`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment