Skip to content

geminiwing/graphql-rails

Repository files navigation

graphql-rails

Installation

After cloning the repository, install the bundle.

$ bundle install

Migrate and seed the DB.

$ rails db:migrate
$ rails db:seed

Run the Rails server.

$ rails server

Browser Test

GraphiQL is an in-browser GraphQL user interface. Type localhost:3000/graphiql in your browser to open the Graphiql UI.

Testing Queries

To fetch all games, type the following query in the query section of the Graphiql.

Operation

query Games {
  games {
    id,
    title
    reviewsCount
    platformNames
  }
}

To fetch a specific game, the query takes a game id.

Operation

query Game($id: ID!) {
  game(id: $id) {
    id
    title
  }
}

Provide the game id in the "variables" section of the Graphiql UI. Variables

{
  "id": 1
}

Testing Mutations

To create a game

Operation

mutation CreateGame($attributes: GameInput!) {
  createGame(input: {
    attributes: $attributes
  })
  {
    game {
      id,
      title,
      platformNames
    }
    errors
  }
}

Variables

{
  "attributes": {
    "title": "XCOM3",
    "description": "Lorem ipsum",
    "platformIds": [1, 2]
  }
}

To delete a game

mutation DeleteGame($id: ID!){
  deleteGame(
    input: { id: $id }
  )
  {
    game {
	    title
    }
    errors
  }
}

variables

{
  "id": 6
}

About

GraphQL example in Ruby on Rails and RSpec

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages