GraphqlApi
Simple api built with Ruby on Rails and GraphQL
Install / Use
/learn @K-Sato1995/GraphqlApiREADME
Setup
Run the commands below.
$ git clone https://github.com/K-Sato1995/GraphqlApi.git
$ bundle install
$ rake db:migrate
Queries and Mutations
Run rails s and send following queries and mutations.
Get posts
{
posts {
id
title
description
comments
}
}
Search Posts
This is just an example. Check out Ransack's README for more search Matchers.
{
posts(q: { status_eq: "PUBLISHED" }) {
id
title
description
status
comments {
id
}
}
}
Get a post
{
post(id: 1) {
id
title
description
comments {
id
content
}
}
}
Creating a post
mutation {
createPost(input: { title: "title1", description: "description1" }) {
post {
id
title
description
}
}
}
Updating a post
mutation {
updatePost(input: { id: 1, title: "Updated", description: "UPdated" }) {
post {
id
title
description
}
}
}
Deleting a post
mutation {
deletePost(input: { id: 1 }) {
post {
id
title
description
}
}
}
Creating a comment
mutation {
createComment(input: { postId: 3, content: "NEW COMMENT" }) {
comment {
id
content
post {
id
title
comments {
id
content
}
}
}
}
}
Creating a User
mutation {
createUser(
input: {
name: "title1"
authProvider: { email: { email: "els@e.scom", password: "passsssord" } }
}
) {
user {
id
name
email
}
}
}
Signing in a User
mutation {
signinUser(
input: { email: { email: "els@e.scom", password: "passsssord" } }
) {
token
}
}
Query for getting all the related information
{
posts {
id
title
description
status
mediaItem {
__typename
... on AudioClip {
id
duration
}
... on VideoClip {
id
previewUrl
resolution
}
}
comments {
id
content
}
}
}
Front End
The front end of this api buit in TypeScript.
