├── Gemfile ├── public └── graphiql-rails │ ├── javascripts │ └── stylesheets ├── config └── routes.rb ├── .codeclimate.yml ├── lib └── graphiql │ ├── rails │ ├── version.rb │ ├── engine.rb │ └── config.rb │ └── rails.rb ├── .gitignore ├── test ├── dummy │ ├── config │ │ ├── routes.rb │ │ ├── boot.rb │ │ ├── environment.rb │ │ ├── application.rb │ │ ├── environments │ │ │ ├── development.rb │ │ │ ├── test.rb │ │ │ └── production.rb │ │ └── secrets.yml │ └── config.ru ├── graphiql │ ├── rails │ │ ├── engine_test.rb │ │ └── config_test.rb │ └── rails_test.rb ├── test_helper.rb └── controllers │ └── editors_controller_test.rb ├── .travis.yml ├── app ├── assets │ └── stylesheets │ │ └── graphiql │ │ └── rails │ │ └── application.css ├── controllers │ └── graphiql │ │ └── rails │ │ └── editors_controller.rb └── views │ └── graphiql │ └── rails │ └── editors │ └── show.html.erb ├── Rakefile ├── package.json ├── webpack.config.js ├── .github └── workflows │ └── test.yml ├── LICENSE ├── graphiql-rails.gemspec ├── readme.md ├── javascript └── application.js └── changelog.md /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | gemspec 3 | -------------------------------------------------------------------------------- /public/graphiql-rails/javascripts: -------------------------------------------------------------------------------- 1 | ../../app/assets/javascripts/graphiql/rails -------------------------------------------------------------------------------- /public/graphiql-rails/stylesheets: -------------------------------------------------------------------------------- 1 | ../../app/assets/stylesheets/graphiql/rails -------------------------------------------------------------------------------- /config/routes.rb: -------------------------------------------------------------------------------- 1 | GraphiQL::Rails::Engine.routes.draw do 2 | get "/", to: "editors#show" 3 | end 4 | -------------------------------------------------------------------------------- /.codeclimate.yml: -------------------------------------------------------------------------------- 1 | engines: 2 | ratings: 3 | paths: 4 | - "**.rb" 5 | exclude_paths: 6 | - spec/**/* 7 | -------------------------------------------------------------------------------- /lib/graphiql/rails/version.rb: -------------------------------------------------------------------------------- 1 | module GraphiQL 2 | module Rails 3 | VERSION = "1.10.5" 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /test/dummy/log 2 | /test/dummy/tmp 3 | /pkg 4 | /graphiql_update 5 | .ruby-version 6 | Gemfile.lock 7 | node_modules/ 8 | yarn.lock 9 | -------------------------------------------------------------------------------- /test/dummy/config/routes.rb: -------------------------------------------------------------------------------- 1 | Rails.application.routes.draw do 2 | mount GraphiQL::Rails::Engine, at: "/graphiql", graphql_path: "/my/graphql/endpoint" 3 | end 4 | -------------------------------------------------------------------------------- /test/dummy/config/boot.rb: -------------------------------------------------------------------------------- 1 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) 2 | 3 | require 'bundler/setup' # Set up gems listed in the Gemfile. 4 | -------------------------------------------------------------------------------- /test/dummy/config.ru: -------------------------------------------------------------------------------- 1 | # This file is used by Rack-based servers to start the application. 2 | 3 | require ::File.expand_path('../config/environment', __FILE__) 4 | run Rails.application 5 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | --- 2 | language: ruby 3 | sudo: false 4 | cache: bundler 5 | env: CODECLIMATE_REPO_TOKEN=06fc877a3d350f9e7c2945da8f3ab04ec2d6861001bc89acf2f020de4d520577 6 | rvm: 7 | - "2.2.2" 8 | -------------------------------------------------------------------------------- /test/dummy/config/environment.rb: -------------------------------------------------------------------------------- 1 | # Load the Rails application. 2 | require File.expand_path('../application', __FILE__) 3 | 4 | # Initialize the Rails application. 5 | Rails.application.initialize! 6 | -------------------------------------------------------------------------------- /test/graphiql/rails/engine_test.rb: -------------------------------------------------------------------------------- 1 | require "test_helper" 2 | 3 | class EngineTest < ActiveSupport::TestCase 4 | test "it is defined" do 5 | assert GraphiQL::Rails::Engine 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /app/assets/stylesheets/graphiql/rails/application.css: -------------------------------------------------------------------------------- 1 | /* 2 | = require ./graphiql-3.8.3 3 | */ 4 | 5 | html, body, #graphiql-container { 6 | height: 100%; 7 | margin: 0; 8 | overflow: hidden; 9 | width: 100%; 10 | } 11 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require 'bundler/setup' 2 | Bundler::GemHelper.install_tasks 3 | 4 | require 'rake/testtask' 5 | 6 | Rake::TestTask.new do |t| 7 | t.libs << "test" << "lib" 8 | t.pattern = "test/**/*_test.rb" 9 | end 10 | 11 | task(default: :test) 12 | -------------------------------------------------------------------------------- /test/graphiql/rails_test.rb: -------------------------------------------------------------------------------- 1 | require "test_helper" 2 | 3 | module GraphiQL 4 | class RailsTest < ActiveSupport::TestCase 5 | test "configs can be set" do 6 | refute GraphiQL::Rails.config.query_params 7 | GraphiQL::Rails.config.query_params = true 8 | assert GraphiQL::Rails.config.query_params 9 | GraphiQL::Rails.config.query_params = false 10 | end 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /test/test_helper.rb: -------------------------------------------------------------------------------- 1 | require "codeclimate-test-reporter" 2 | CodeClimate::TestReporter.start 3 | 4 | ENV["RAILS_ENV"] = "test" 5 | require File.expand_path("../dummy/config/environment.rb", __FILE__) 6 | require "rails/test_help" 7 | require "rails/generators" 8 | require 'minitest/mock' 9 | 10 | Rails.backtrace_cleaner.remove_silencers! 11 | 12 | Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f } 13 | -------------------------------------------------------------------------------- /app/controllers/graphiql/rails/editors_controller.rb: -------------------------------------------------------------------------------- 1 | module GraphiQL 2 | module Rails 3 | class EditorsController < ActionController::Base 4 | def show 5 | end 6 | 7 | helper_method :graphql_endpoint_path 8 | def graphql_endpoint_path 9 | params[:graphql_path] || raise(%|You must include `graphql_path: "/my/endpoint"` when mounting GraphiQL::Rails::Engine|) 10 | end 11 | end 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /test/dummy/config/application.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path('../boot', __FILE__) 2 | 3 | require "action_controller/railtie" 4 | require "action_mailer/railtie" 5 | require "rails/test_unit/railtie" 6 | 7 | # Require the gems listed in Gemfile, including any gems 8 | # you've limited to :test, :development, or :production. 9 | Bundler.require(*Rails.groups) 10 | 11 | module Dummy 12 | class Application < Rails::Application 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "graphiql-rails-build-pipeline", 3 | "devDependencies": { 4 | "@graphiql/toolkit": "0.11.1", 5 | "graphiql": "3.8.3", 6 | "graphql": "16.10.0", 7 | "react": "18.0.0", 8 | "react-dom": "18.0.0", 9 | "webpack": "5.98.0", 10 | "webpack-cli": "^6.0.1" 11 | }, 12 | "private": true, 13 | "scripts": { 14 | "build": "webpack && rm app/assets/javascripts/graphiql/rails/application.js.LICENSE.txt" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /webpack.config.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const webpack = require('webpack'); 3 | 4 | new webpack.DefinePlugin({ 5 | 'process.env.NODE_ENV': '"PRODUCTION"', 6 | }); 7 | 8 | module.exports = { 9 | entry: './javascript/application.js', 10 | mode: "production", 11 | output: { 12 | filename: 'application.js', 13 | path: path.resolve(__dirname, 'app/assets/javascripts/graphiql/rails'), 14 | chunkFormat: false, 15 | }, 16 | devtool: false 17 | }; 18 | -------------------------------------------------------------------------------- /lib/graphiql/rails/engine.rb: -------------------------------------------------------------------------------- 1 | module GraphiQL 2 | module Rails 3 | class Engine < ::Rails::Engine 4 | isolate_namespace GraphiQL::Rails 5 | 6 | if defined?(Sprockets) && Sprockets::VERSION.chr.to_i >= 4 7 | initializer 'graphiql.assets.precompile' do |app| 8 | app.config.assets.precompile += ["graphiql/rails/application.css"] 9 | end 10 | elsif !defined?(Propshaft) 11 | initializer 'graphiql.assets.public' do |app| 12 | app.middleware.use(ActionDispatch::Static, "#{root}/public") 13 | end 14 | end 15 | end 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: Tests 2 | on: pull_request 3 | 4 | jobs: 5 | test: 6 | strategy: 7 | fail-fast: false 8 | matrix: 9 | include: 10 | - gemfile: Gemfile 11 | ruby: 3.0 12 | - gemfile: Gemfile 13 | ruby: 3.4 14 | runs-on: ubuntu-20.04 15 | steps: 16 | - run: echo BUNDLE_GEMFILE=${{ matrix.gemfile }} > $GITHUB_ENV 17 | - uses: actions/checkout@v2 18 | - uses: ruby/setup-ruby@v1 19 | with: 20 | ruby-version: ${{ matrix.ruby }} 21 | bundler-cache: true 22 | bundler: ${{ matrix.bundler || 'default' }} 23 | - run: bundle exec rake test 24 | -------------------------------------------------------------------------------- /lib/graphiql/rails.rb: -------------------------------------------------------------------------------- 1 | require "rails" 2 | 3 | if ActiveSupport::Inflector.method(:inflections).arity == 0 4 | # Rails 3 does not take a language in inflections. 5 | ActiveSupport::Inflector.inflections do |inflect| 6 | inflect.acronym("GraphiQL") 7 | end 8 | else 9 | ActiveSupport::Inflector.inflections(:en) do |inflect| 10 | inflect.acronym("GraphiQL") 11 | end 12 | end 13 | 14 | require "graphiql/rails/config" 15 | require "graphiql/rails/engine" 16 | require "graphiql/rails/version" 17 | 18 | module GraphiQL 19 | module Rails 20 | class << self 21 | attr_accessor :config 22 | end 23 | 24 | self.config = Config.new 25 | end 26 | end 27 | -------------------------------------------------------------------------------- /test/dummy/config/environments/development.rb: -------------------------------------------------------------------------------- 1 | Rails.application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb. 3 | 4 | # In the development environment your application's code is reloaded on 5 | # every request. This slows down response time but is perfect for development 6 | # since you don't have to restart the web server when you make code changes. 7 | config.cache_classes = false 8 | 9 | # Do not eager load code on boot. 10 | config.eager_load = false 11 | 12 | # Show full error reports and disable caching. 13 | config.consider_all_requests_local = true 14 | config.action_controller.perform_caching = false 15 | 16 | # Don't care if the mailer can't send. 17 | config.action_mailer.raise_delivery_errors = false 18 | 19 | # Print deprecation notices to the Rails logger. 20 | config.active_support.deprecation = :log 21 | 22 | # Raises error for missing translations 23 | # config.action_view.raise_on_missing_translations = true 24 | end 25 | -------------------------------------------------------------------------------- /test/dummy/config/secrets.yml: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Your secret key is used for verifying the integrity of signed cookies. 4 | # If you change this key, all old signed cookies will become invalid! 5 | 6 | # Make sure the secret is at least 30 characters and all random, 7 | # no regular words or you'll be exposed to dictionary attacks. 8 | # You can use `rake secret` to generate a secure secret key. 9 | 10 | # Make sure the secrets in this file are kept private 11 | # if you're sharing your code publicly. 12 | 13 | development: 14 | secret_key_base: 78457268f3f9b0c3efa88ac47c71f8277dd1723a5d406ac9e81aa1d179c7881200fdc23ee1d2be84887fb18490c380563d4a009eb887829ec0309d00208a7a7f 15 | 16 | test: 17 | secret_key_base: 79a80a1136851a8ca2823ddb922c3827d8f728bc223a1e713313d919116b5b34ebf28dcd553f3bde35ff27e5c35bcdb93782e61c02d1b493390b4f0aa9767858 18 | 19 | # Do not keep production secrets in the repository, 20 | # instead read values from the environment. 21 | production: 22 | secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> 23 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Robert Mosolgo 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /graphiql-rails.gemspec: -------------------------------------------------------------------------------- 1 | $LOAD_PATH.push File.expand_path("../lib", __FILE__) 2 | 3 | require "graphiql/rails/version" 4 | require "date" 5 | 6 | Gem::Specification.new do |s| 7 | s.name = 'graphiql-rails' 8 | s.version = GraphiQL::Rails::VERSION 9 | s.date = Date.today.to_s 10 | s.summary = "A mountable GraphiQL endpoint for Rails" 11 | s.description = "Use the GraphiQL IDE for GraphQL with Ruby on Rails. This gem includes an engine, a controller and a view for integrating GraphiQL with your app." 12 | s.homepage = 'http://github.com/rmosolgo/graphiql-rails' 13 | s.authors = ["Robert Mosolgo"] 14 | s.email = ['rdmosolgo@gmail.com'] 15 | s.license = "MIT" 16 | s.required_ruby_version = '>= 2.1.0' # bc optional keyword args 17 | 18 | s.files = Dir["{app,config,lib,public}/**/*"] 19 | 20 | s.add_runtime_dependency "railties" 21 | 22 | s.add_development_dependency "rails" 23 | s.add_development_dependency "sqlite3" 24 | s.add_development_dependency "codeclimate-test-reporter", '~>0.4' 25 | s.add_development_dependency "minitest", "~> 5" 26 | s.add_development_dependency "minitest-focus", "~> 1.1" 27 | s.add_development_dependency "minitest-reporters", "~>1.0" 28 | s.add_development_dependency "rake" 29 | s.add_development_dependency "puma" 30 | end 31 | -------------------------------------------------------------------------------- /test/graphiql/rails/config_test.rb: -------------------------------------------------------------------------------- 1 | require "test_helper" 2 | 3 | class ConfigTest < ActiveSupport::TestCase 4 | class MockViewContext 5 | attr_accessor :customer_header_value 6 | 7 | def form_authenticity_token 8 | "abc-123" 9 | end 10 | end 11 | 12 | setup do 13 | @config = GraphiQL::Rails::Config.new 14 | @config.headers["X-Custom-Header"] = ->(view_context) { view_context.customer_header_value } 15 | @view_context = MockViewContext.new 16 | end 17 | 18 | test "it adds CSRF header if requested" do 19 | assert_equal "abc-123", @config.resolve_headers(@view_context)["X-CSRF-Token"] 20 | @config.csrf = false 21 | assert_nil @config.resolve_headers(@view_context)["X-CSRF-Token"] 22 | end 23 | 24 | test "it adds JSON header by default" do 25 | assert_equal "application/json", @config.resolve_headers(@view_context)["Content-Type"] 26 | end 27 | 28 | test "when the customer header value is nil it is not added" do 29 | @view_context.customer_header_value = nil 30 | assert_equal @config.resolve_headers(@view_context).has_key?("X-Custom-Header"), false 31 | end 32 | 33 | test "when the customer header value is not nil it is added" do 34 | @view_context.customer_header_value = "some-value" 35 | assert_equal "some-value", @config.resolve_headers(@view_context)["X-Custom-Header"] 36 | end 37 | end 38 | -------------------------------------------------------------------------------- /app/views/graphiql/rails/editors/show.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 |