alkesh26 / demo_graphql

GraphQL in Ruby on Rails

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

README

GraphQL integration with Ruby on Rails.

Gem used for GraphQL:

graphql

Steps to run the application locally

  1. Clone the repository

  2. Install Ruby 3.1.2 using RVM or Rbenv

  3. Navigate to the project and execute bundle install

  4. Run migrations

    rake db:create
    rake db:migrate
    
  5. Seed data

    rake db:seed
    
  6. Start the rails server and navigate to localhost:3000/graphiql

    rails s
    
  7. Available querys and mutation

    • Fetch Post with id = 1
    query {
      fetchPost(id: 1) {
        id
        title
        description
        createdAt
        updatedAt
      }
    }
    
    • Fetch all comments
    query {
      fetchComments {
        id
        title
        content
        postId
        createdAt
        updatedAt
      }
    }
    
    • Fetch all comments with post details
    query {
      fetchComments {
        id
        title
        content
        post {
          id
          title
          description
        }
        createdAt
        updatedAt
      }
    }
    
    • Mutation to create a Post
    mutation {
      createPost(input: { params: { title: "GraphQL blog", description: "GraphQL and Ruby on Rails"  }}) {
        post {
          id
          title
          description
        }
      }
    }
    

About

GraphQL in Ruby on Rails


Languages

Language:Ruby 78.5%Language:HTML 12.5%Language:Dockerfile 4.2%Language:JavaScript 2.8%Language:CSS 1.6%Language:Shell 0.4%