Example Rails app using GitHub's GraphQL API
Перейти к файлу
Joshua Peek 3acc6c858b Comment copy editing 2016-09-13 16:59:46 -07:00
app Comment copy editing 2016-09-13 16:59:46 -07:00
bin Generate Rails scaffold 2016-09-10 15:22:44 +09:00
config Remove empty file 2016-09-12 13:40:11 +09:00
db Import schema 2016-09-13 13:28:00 -07:00
lib/tasks Load environment first 2016-09-11 10:02:53 +09:00
public Add basic layout styles 2016-09-10 15:24:31 +09:00
.gitignore Generate Rails scaffold 2016-09-10 15:22:44 +09:00
Gemfile Upgrade graphql-client 2016-09-11 22:54:52 +09:00
Gemfile.lock Upgrade graphql-client 2016-09-11 22:54:52 +09:00
LICENSE Add LICENSE 2016-09-11 09:40:25 +09:00
README.md Link to other resources 2016-09-13 16:57:13 -07:00
Rakefile Generate Rails scaffold 2016-09-10 15:22:44 +09:00
config.ru Generate Rails scaffold 2016-09-10 15:22:44 +09:00

README.md

GitHub GraphQL Rails example application

Demonstrates how to use the graphql-client gem to build a simple repository listing web view against the GitHub GraphQL API.

The application structure is setup like a typical Rails app using controllers, views and routes with one key difference, no models. This app doesn't connect directly to any database. All the data is being fetched remotely from the GitHub GraphQL API. Instead of declaring resource models, data queries are declared right along side their usage in controllers and views. This allows an efficient single to be constructed rather than making numerous REST requests to render a single view.

Table of Contents

Jump right into the code and read the inline documentation. The following is a suggested reading order:

  1. app/controller/repositories_controller.rb defines the top level GraphQL queries to fetch repository list and show pages.
  2. app/views/repositories/index.html.erb shows the root template's listing query and composition over subviews.
  3. app/views/repositories/_repositories.html.erb makes use of GraphQL connections to show the first couple items and a "load more" button.
  4. app/views/repositories/show.html.erb shows the root template for the repository show page.
  5. app/controller/application_controller.rb defines controller helpers for executing GraphQL query requests.
  6. config/application.rb configures GraphQL::Client to point to the GitHub GraphQL endpoint.

Running locally

First, you'll need a GitHub API access token to make GraphQL API requests. This should be set as a GITHUB_ACCESS_TOKEN environment variable as configured in config/secrets.yml.

$ git clone https://github.com/github/github-graphql-rails-example
$ cd github-graphql-rails-example/
$ bundle install
$ GITHUB_ACCESS_TOKEN=abc123 bin/rails

And visit http://localhost:3000/.

See Also