Β
Β
- authentication system
- users can create, read, update and delete blogs
- users can comment the blog of other user
- users can clap the blog of other user
- users can save the blog of other user to favorites
Β
Install dependencies:
bundle install
rails db:setup
Starting the server:
rails server
Opening the application:
open http://localhost:3000/
or
http://localhost:3000/graphiql
Β
- GraphqlController - GraphQL controller (api entry point)
- GraphqlTutorialSchema - the schema definition
- Mutations - root mutations
- Queries - root queries
-
SignIn - mutation
-
SignUp - mutation
-
CreatePost - mutation
-
UpdatePost - mutation
-
DeletePost - mutation
-
AddComment - mutation
-
AddClap - mutation
-
AddFavorite - mutation
-
DeleteFavorite - mutation
Β
Sign Up:
mutation {
signUp(input: { name: "Leonardo da Vinci", credentials: { email: "leonardo@example.com", password: "leonardo123" } } ) {
user {
id
email
name
}
success
errors
}
}
Create new user token:
mutation {
signIn(input: { credentials: { email: "leonardo@example.com", password: "leonardo123" } }) {
user {
id
email
name
}
success
token
errors
}
}
Create post:
mutation {
createPost(input: { title:"How to create a GraphQL Blog with Rails", body:"Vitae eaque dolor. Et amet laudantium. Molestiae velit quos." }) {
post {
id
title
content
postedAt
updatedAt
postedBy {
name
}
}
success
errors
}
}
Update post:
mutation {
updatePost(input: { id:"1", title:"How to create a React App", body:"Vitae eaque dolor. Et amet laudantium. Molestiae velit quos."}) {
post {
id
title
content
postedAt
updatedAt
postedBy {
name
}
}
updated
errors
}
}
Destroy post:
mutation {
destroyPost(input: { id:"1"}) {
post {
id
title
content
postedAt
updatedAt
postedBy {
name
}
}
deleted
errors
}
}
Add Comment:
mutation {
addComment(input: { postId:"1", content:"I love your Post"} ) {
comment {
id
content
commentedBy {
id
name
}
}
errors
success
}
}
Add Clap
mutation {
addClap(input: {postId:"3"}){
clap {
clappedBy {
name
}
}
success
errors
}
}
Add Favorite
mutation {
addFavorite(input: {postId:"3"}){
favorite {
title
}
success
errors
}
}
Delete Favorite
mutation {
deleteFavorite(input: {postId:"3"}){
favorite {
title
}
errors
deleted
}
}
Β
This sample app is based on graphql-ruby tutorial from howtographql
Β
Lookin' at the source code huh? Be sure to drop me a line! I'd love to chat, whether it's about code, design, sports, coffee, books, or anything in between. π¨π»βπ»βοΈ