Coder Social home page Coder Social logo

github-graphql-rails-example's Introduction

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 request 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 server

And visit http://localhost:3000/.

See Also

github-graphql-rails-example's People

Contributors

josh avatar krider2010 avatar mikrobi avatar nakajima avatar nickvanw avatar oguzbilgic avatar sebamelgar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

github-graphql-rails-example's Issues

Upgrade to Rails 5.2, GraphQL Client + GraphQL

Right now, this project is on an old version of Rails, as well as a very old version of graphql-client. Right now, the railties in the latest release of graphql-client make this not possible, which should be fixed.

Y'all got any more of them "Tests"?

Hey -

Thanks for putting this example out there, and sharing it with the world.

However, next thing that will happen is we'll want to know how to test it.

How about a simple example? RSpec would be nice. Anything you've got can be expanded upon by us.

Thanks!

Import public schema

Need to check in a db/schema.json with just the types and fields we're exposing for the GraphQL Alpha.

GraphQL Schema development reloading bug

When app/controllers/repositories_controller.rb is modified in dev, the next request will fail on an unloaded GraphQL::BOOLEAN_TYPE::ALLOWED_INPUTS.

uninitialized constant ALLOWED_INPUTS

graphql (0.18.10) lib/graphql/boolean_type.rb:8:in `block (2 levels) in <top (required)>'
graphql (0.18.10) lib/graphql/scalar_type.rb:54:in `call'
graphql (0.18.10) lib/graphql/scalar_type.rb:54:in `coerce_non_null_input'
graphql (0.18.10) lib/graphql/base_type.rb:111:in `coerce_input'
graphql (0.18.10) lib/graphql/schema/validation.rb:103:in `block in <module:Rules>'
graphql (0.18.10) lib/graphql/schema/validation.rb:18:in `call'
graphql (0.18.10) lib/graphql/schema/validation.rb:18:in `block in validate'
graphql (0.18.10) lib/graphql/schema/validation.rb:18:in `each'
graphql (0.18.10) lib/graphql/schema/validation.rb:18:in `reduce'
graphql (0.18.10) lib/graphql/schema/validation.rb:18:in `validate'
graphql (0.18.10) lib/graphql/schema/validation.rb:79:in `block (2 levels) in assert_named_items_are_valid'
graphql (0.18.10) lib/graphql/schema/validation.rb:78:in `each'
graphql (0.18.10) lib/graphql/schema/validation.rb:78:in `block in assert_named_items_are_valid'
graphql (0.18.10) lib/graphql/schema/validation.rb:18:in `call'
graphql (0.18.10) lib/graphql/schema/validation.rb:18:in `block in validate'
graphql (0.18.10) lib/graphql/schema/validation.rb:18:in `each'
graphql (0.18.10) lib/graphql/schema/validation.rb:18:in `reduce'
graphql (0.18.10) lib/graphql/schema/validation.rb:18:in `validate'
graphql (0.18.10) lib/graphql/schema/validation.rb:79:in `block (2 levels) in assert_named_items_are_valid'
graphql (0.18.10) lib/graphql/schema/validation.rb:78:in `each'
graphql (0.18.10) lib/graphql/schema/validation.rb:78:in `block in assert_named_items_are_valid'
graphql (0.18.10) lib/graphql/schema/validation.rb:18:in `call'
graphql (0.18.10) lib/graphql/schema/validation.rb:18:in `block in validate'
graphql (0.18.10) lib/graphql/schema/validation.rb:18:in `each'
graphql (0.18.10) lib/graphql/schema/validation.rb:18:in `reduce'
graphql (0.18.10) lib/graphql/schema/validation.rb:18:in `validate'
graphql (0.18.10) lib/graphql/schema/reduce_types.rb:61:in `validate_type'
graphql (0.18.10) lib/graphql/schema/reduce_types.rb:28:in `reduce_type'
graphql (0.18.10) lib/graphql/schema/reduce_types.rb:37:in `block in crawl_type'
graphql (0.18.10) lib/graphql/schema/reduce_types.rb:36:in `each'
graphql (0.18.10) lib/graphql/schema/reduce_types.rb:36:in `crawl_type'
graphql (0.18.10) lib/graphql/schema/reduce_types.rb:30:in `reduce_type'
graphql (0.18.10) lib/graphql/schema/reduce_types.rb:9:in `block in reduce'
graphql (0.18.10) lib/graphql/schema/reduce_types.rb:8:in `each'
graphql (0.18.10) lib/graphql/schema/reduce_types.rb:8:in `reduce'
graphql (0.18.10) lib/graphql/schema.rb:129:in `types'
graphql (0.18.10) lib/graphql/static_validation/rules/variables_are_input_types.rb:16:in `validate_is_input_type'
graphql (0.18.10) lib/graphql/static_validation/rules/variables_are_input_types.rb:8:in `block in validate'
graphql (0.18.10) lib/graphql/language/visitor.rb:73:in `call'
graphql (0.18.10) lib/graphql/language/visitor.rb:73:in `block in apply_hooks'
graphql (0.18.10) lib/graphql/language/visitor.rb:73:in `each'
graphql (0.18.10) lib/graphql/language/visitor.rb:73:in `reduce'
graphql (0.18.10) lib/graphql/language/visitor.rb:73:in `apply_hooks'
graphql (0.18.10) lib/graphql/language/visitor.rb:61:in `begin_visit'
graphql (0.18.10) lib/graphql/language/visitor.rb:51:in `visit_node'
graphql (0.18.10) lib/graphql/language/visitor.rb:53:in `block in visit_node'
graphql (0.18.10) lib/graphql/language/visitor.rb:53:in `each'
graphql (0.18.10) lib/graphql/language/visitor.rb:53:in `reduce'
graphql (0.18.10) lib/graphql/language/visitor.rb:53:in `visit_node'
graphql (0.18.10) lib/graphql/language/visitor.rb:53:in `block in visit_node'
graphql (0.18.10) lib/graphql/language/visitor.rb:53:in `each'
graphql (0.18.10) lib/graphql/language/visitor.rb:53:in `reduce'
graphql (0.18.10) lib/graphql/language/visitor.rb:53:in `visit_node'
graphql (0.18.10) lib/graphql/language/visitor.rb:45:in `visit'
graphql (0.18.10) lib/graphql/static_validation/validator.rb:33:in `validate'
graphql-client (0.0.14) lib/graphql/client.rb:120:in `parse'
app/controllers/repositories_controller.rb:2:in `<class:RepositoriesController>'
app/controllers/repositories_controller.rb:1:in `<top (required)>'
activesupport (5.0.0) lib/active_support/dependencies/interlock.rb:12:in `block in loading'
activesupport (5.0.0) lib/active_support/concurrency/share_lock.rb:117:in `exclusive'
activesupport (5.0.0) lib/active_support/dependencies/interlock.rb:11:in `loading'
activesupport (5.0.0) lib/active_support/inflector/methods.rb:268:in `const_get'
activesupport (5.0.0) lib/active_support/inflector/methods.rb:268:in `block in constantize'
activesupport (5.0.0) lib/active_support/inflector/methods.rb:266:in `each'
activesupport (5.0.0) lib/active_support/inflector/methods.rb:266:in `inject'
activesupport (5.0.0) lib/active_support/inflector/methods.rb:266:in `constantize'
actionpack (5.0.0) lib/action_dispatch/http/request.rb:93:in `controller_class'
actionpack (5.0.0) lib/action_dispatch/routing/route_set.rb:44:in `controller'
actionpack (5.0.0) lib/action_dispatch/routing/route_set.rb:30:in `serve'
actionpack (5.0.0) lib/action_dispatch/journey/router.rb:39:in `block in serve'
actionpack (5.0.0) lib/action_dispatch/journey/router.rb:26:in `each'
actionpack (5.0.0) lib/action_dispatch/journey/router.rb:26:in `serve'
actionpack (5.0.0) lib/action_dispatch/routing/route_set.rb:725:in `call'
rack (2.0.1) lib/rack/etag.rb:25:in `call'
rack (2.0.1) lib/rack/conditional_get.rb:25:in `call'
rack (2.0.1) lib/rack/head.rb:12:in `call'
rack (2.0.1) lib/rack/session/abstract/id.rb:222:in `context'
rack (2.0.1) lib/rack/session/abstract/id.rb:216:in `call'
actionpack (5.0.0) lib/action_dispatch/middleware/cookies.rb:613:in `call'
actionpack (5.0.0) lib/action_dispatch/middleware/callbacks.rb:38:in `block in call'
activesupport (5.0.0) lib/active_support/callbacks.rb:97:in `__run_callbacks__'
activesupport (5.0.0) lib/active_support/callbacks.rb:750:in `_run_call_callbacks'
activesupport (5.0.0) lib/active_support/callbacks.rb:90:in `run_callbacks'
actionpack (5.0.0) lib/action_dispatch/middleware/callbacks.rb:36:in `call'
actionpack (5.0.0) lib/action_dispatch/middleware/executor.rb:12:in `call'
actionpack (5.0.0) lib/action_dispatch/middleware/remote_ip.rb:79:in `call'
actionpack (5.0.0) lib/action_dispatch/middleware/debug_exceptions.rb:49:in `call'
actionpack (5.0.0) lib/action_dispatch/middleware/show_exceptions.rb:31:in `call'
railties (5.0.0) lib/rails/rack/logger.rb:36:in `call_app'
railties (5.0.0) lib/rails/rack/logger.rb:24:in `block in call'
activesupport (5.0.0) lib/active_support/tagged_logging.rb:70:in `block in tagged'
activesupport (5.0.0) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (5.0.0) lib/active_support/tagged_logging.rb:70:in `tagged'
railties (5.0.0) lib/rails/rack/logger.rb:24:in `call'
actionpack (5.0.0) lib/action_dispatch/middleware/request_id.rb:24:in `call'
rack (2.0.1) lib/rack/method_override.rb:22:in `call'
rack (2.0.1) lib/rack/runtime.rb:22:in `call'
activesupport (5.0.0) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
actionpack (5.0.0) lib/action_dispatch/middleware/executor.rb:12:in `call'
actionpack (5.0.0) lib/action_dispatch/middleware/static.rb:136:in `call'
rack (2.0.1) lib/rack/sendfile.rb:111:in `call'
railties (5.0.0) lib/rails/engine.rb:522:in `call'
rack (2.0.1) lib/rack/handler/webrick.rb:86:in `service'
/usr/local/var/rbenv/versions/2.2.4/lib/ruby/2.2.0/webrick/httpserver.rb:138:in `service'
/usr/local/var/rbenv/versions/2.2.4/lib/ruby/2.2.0/webrick/httpserver.rb:94:in `run'
/usr/local/var/rbenv/versions/2.2.4/lib/ruby/2.2.0/webrick/server.rb:294:in `block in start_thread'

Order by updated date

Hi,
How can we order the repositories order by updated at like list which is on the Github profile page?

Open Source

Make this public on Universe release day.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.