rmosolgo / graphiql-rails Goto Github PK
View Code? Open in Web Editor NEWMount the GraphiQL query editor in a Rails app
License: MIT License
Mount the GraphiQL query editor in a Rails app
License: MIT License
FROM ruby:2.5.1-alpine3.7
RUN apk add --no-cache build-base sqlite-dev tzdata nodejs=8.9.3-r1
ENV RAILS_VERSION 5.2.0
RUN gem install rails --version "$RAILS_VERSION"
RUN rails new --skip-bundle --database=sqlite3 dummy_app \
&& cd dummy_app \
&& echo 'gem "graphiql-rails", "1.4.10"' >> Gemfile \
&& bundle
WORKDIR /dummy_app
docker build --tag giql .
docker run --rm --interactive --tty giql sh
RAILS_ENV=development bundle exec rake assets:precompile
, then assets compilation succeeds:/dummy_app # RAILS_ENV=development bundle exec rake assets:precompile
Yarn executable was not detected in the system.
Download Yarn at https://yarnpkg.com/en/docs/install
I, [2018-04-18T10:16:37.489067 #35] INFO -- : Writing /dummy_app/public/assets/application-f360afb1ab93d9c96eeba633778fb50e4860f856ce8e22b383401daaddc917e8.js
I, [2018-04-18T10:16:37.501698 #35] INFO -- : Writing /dummy_app/public/assets/application-f360afb1ab93d9c96eeba633778fb50e4860f856ce8e22b383401daaddc917e8.js.gz
I, [2018-04-18T10:16:37.505899 #35] INFO -- : Writing /dummy_app/public/assets/application-f0d704deea029cf000697e2c0181ec173a1b474645466ed843eb5ee7bb215794.css
I, [2018-04-18T10:16:37.506153 #35] INFO -- : Writing /dummy_app/public/assets/application-f0d704deea029cf000697e2c0181ec173a1b474645466ed843eb5ee7bb215794.css.gz
I, [2018-04-18T10:16:37.984407 #35] INFO -- : Writing /dummy_app/public/assets/graphiql/rails/application-09ecfeeb9885e7c9d9529f06c4360e92312b9c15f455df0e6d29ed6098ae85ee.js
I, [2018-04-18T10:16:37.984569 #35] INFO -- : Writing /dummy_app/public/assets/graphiql/rails/application-09ecfeeb9885e7c9d9529f06c4360e92312b9c15f455df0e6d29ed6098ae85ee.js.gz
I, [2018-04-18T10:16:38.003801 #35] INFO -- : Writing /dummy_app/public/assets/graphiql/rails/application-2fbb932618633e58c4f72482da2714cb25f2c9fc91e26fb33df63a1e5b47f74c.css
I, [2018-04-18T10:16:38.003948 #35] INFO -- : Writing /dummy_app/public/assets/graphiql/rails/application-2fbb932618633e58c4f72482da2714cb25f2c9fc91e26fb33df63a1e5b47f74c.css.gz
RAILS_ENV=production bundle exec rake assets:precompile
, then assets compilation fails with the following error:/dummy_app # RAILS_ENV=production bundle exec rake assets:precompile
Yarn executable was not detected in the system.
Download Yarn at https://yarnpkg.com/en/docs/install
I, [2018-04-18T10:15:09.415186 #8] INFO -- : Writing /dummy_app/public/assets/application-3d9f5ba74dcfc600bc2f9dc7e80aa5ac058cb0eecd52dec7490cb3dda09307d5.js
I, [2018-04-18T10:15:09.428073 #8] INFO -- : Writing /dummy_app/public/assets/application-3d9f5ba74dcfc600bc2f9dc7e80aa5ac058cb0eecd52dec7490cb3dda09307d5.js.gz
I, [2018-04-18T10:15:09.436581 #8] INFO -- : Writing /dummy_app/public/assets/application-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855.css
I, [2018-04-18T10:15:09.436894 #8] INFO -- : Writing /dummy_app/public/assets/application-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855.css.gz
rake aborted!
Uglifier::Error: In strict mode code, functions can only be declared at top level or immediately within another function.
/usr/local/bundle/gems/uglifier-4.1.9/lib/uglifier.rb:234:in `parse_result'
/usr/local/bundle/gems/uglifier-4.1.9/lib/uglifier.rb:216:in `run_uglifyjs'
/usr/local/bundle/gems/uglifier-4.1.9/lib/uglifier.rb:168:in `compile'
/usr/local/bundle/gems/sprockets-3.7.1/lib/sprockets/uglifier_compressor.rb:53:in `call'
/usr/local/bundle/gems/sprockets-3.7.1/lib/sprockets/uglifier_compressor.rb:28:in `call'
/usr/local/bundle/gems/sprockets-3.7.1/lib/sprockets/processor_utils.rb:75:in `call_processor'
/usr/local/bundle/gems/sprockets-3.7.1/lib/sprockets/processor_utils.rb:57:in `block in call_processors'
/usr/local/bundle/gems/sprockets-3.7.1/lib/sprockets/processor_utils.rb:56:in `reverse_each'
/usr/local/bundle/gems/sprockets-3.7.1/lib/sprockets/processor_utils.rb:56:in `call_processors'
/usr/local/bundle/gems/sprockets-3.7.1/lib/sprockets/loader.rb:134:in `load_from_unloaded'
/usr/local/bundle/gems/sprockets-3.7.1/lib/sprockets/loader.rb:60:in `block in load'
/usr/local/bundle/gems/sprockets-3.7.1/lib/sprockets/loader.rb:317:in `fetch_asset_from_dependency_cache'
/usr/local/bundle/gems/sprockets-3.7.1/lib/sprockets/loader.rb:44:in `load'
/usr/local/bundle/gems/sprockets-3.7.1/lib/sprockets/cached_environment.rb:20:in `block in initialize'
/usr/local/bundle/gems/sprockets-3.7.1/lib/sprockets/cached_environment.rb:47:in `load'
/usr/local/bundle/gems/sprockets-3.7.1/lib/sprockets/base.rb:66:in `find_asset'
/usr/local/bundle/gems/sprockets-3.7.1/lib/sprockets/base.rb:73:in `find_all_linked_assets'
/usr/local/bundle/gems/sprockets-3.7.1/lib/sprockets/manifest.rb:142:in `block in find'
/usr/local/bundle/gems/sprockets-3.7.1/lib/sprockets/legacy.rb:114:in `block (2 levels) in logical_paths'
/usr/local/bundle/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:228:in `block in stat_tree'
/usr/local/bundle/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:212:in `block in stat_directory'
/usr/local/bundle/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:209:in `each'
/usr/local/bundle/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:209:in `stat_directory'
/usr/local/bundle/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:227:in `stat_tree'
/usr/local/bundle/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:231:in `block in stat_tree'
/usr/local/bundle/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:212:in `block in stat_directory'
/usr/local/bundle/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:209:in `each'
/usr/local/bundle/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:209:in `stat_directory'
/usr/local/bundle/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:227:in `stat_tree'
/usr/local/bundle/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:231:in `block in stat_tree'
/usr/local/bundle/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:212:in `block in stat_directory'
/usr/local/bundle/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:209:in `each'
/usr/local/bundle/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:209:in `stat_directory'
/usr/local/bundle/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:227:in `stat_tree'
/usr/local/bundle/gems/sprockets-3.7.1/lib/sprockets/legacy.rb:105:in `each'
/usr/local/bundle/gems/sprockets-3.7.1/lib/sprockets/legacy.rb:105:in `block in logical_paths'
/usr/local/bundle/gems/sprockets-3.7.1/lib/sprockets/legacy.rb:104:in `each'
/usr/local/bundle/gems/sprockets-3.7.1/lib/sprockets/legacy.rb:104:in `logical_paths'
/usr/local/bundle/gems/sprockets-3.7.1/lib/sprockets/manifest.rb:140:in `find'
/usr/local/bundle/gems/sprockets-3.7.1/lib/sprockets/manifest.rb:185:in `compile'
/usr/local/bundle/gems/sprockets-rails-3.2.1/lib/sprockets/rails/task.rb:68:in `block (3 levels) in define'
/usr/local/bundle/gems/sprockets-3.7.1/lib/rake/sprocketstask.rb:147:in `with_logger'
/usr/local/bundle/gems/sprockets-rails-3.2.1/lib/sprockets/rails/task.rb:67:in `block (2 levels) in define'
/usr/local/bundle/gems/rake-12.3.1/exe/rake:27:in `<top (required)>'
/usr/local/bundle/bin/bundle:104:in `load'
/usr/local/bundle/bin/bundle:104:in `<main>'
Tasks: TOP => assets:precompile
(See full trace by running task with --trace)
The error doesn't happen if I remove gem "graphiql-rails"
in the Gemfile.
I'm currently learning Rails API-only development and versioning, and I'd like to implement GraphQL and play with GraphiQL. I'm currently getting the error above. It's probably a simple issue, and I apologize, but I'm stuck.
My routes are as follows:
Rails.application.routes.draw do
if Rails.env.development?
mount GraphiQL::Rails::Engine, at: "/graphiql", graphql_path: "/graphql"
end
scope module: :v3, constraints: ApiVersion.new('v3') do
post 'graphql', to: 'graphql#execute'
end
scope module: :v2, constraints: ApiVersion.new('v2') do
resources :todos, only: :index
end
scope module: :v1, constraints: ApiVersion.new('v1', true) do
resources :todos do
resources :items
end
end
post 'auth/login', to: 'authentication#authenticate'
post 'signup', to: 'users#create'
end
Thanks in advance. Any insight would be appreciated.
Since the gem hasn't been updated recently, I decided to post this issue in the hopes it helps other people interested in using a newer GraphiQL release.
NOTE: This uses Webpacker, you can accomplish this with Sprockets by essentially doing what the graphiql-rails gem already does, but in your own app. aka, just vendor react and graphiql inside your application.
So now that GraphiQL is at 1.0.0, I wanted to update to it in my app. I don't have a specific guide for this that I'm going to write, but you can take a look at my PR for this and my summary of the changes below. connorshea/vglist#1262
Essentially, I just do this:
/graphiql
with no layout and load the graphiql.js pack in it.And it'll work in production :) Though, you should make sure to take proper security precautions to make sure the GraphiQL instance isn't abused. (I made some relevant changes for using API tokens here: connorshea/vglist#1329)
I don't have any interest in making a gem to do this, sorry! You'll have to set it up yourself. If someone else wants to try, feel free :D
This issue looks like a zombie of #13 (Assets are not accessible in API-only app), which was closed a year ago. I followed the advice of jam35L in that issue with no effect. Here is the log output:
Started GET "/graphiql/admin" for 10.242.2.16 at 2017-10-24 13:40:33 -0400
Processing by GraphiQL::Rails::EditorsController#show as HTML
Parameters: {"graphql_path"=>"/queries/admin"}
Rendered /nhome/kkaplan/.rbenv/versions/2.1.7/lib/ruby/gems/2.1.0/gems/graphiql-rails-1.4.5/app/views/graphiql/rails/editors/show.html.erb (5.9ms)
Completed 200 OK in 25.0ms (Views: 24.6ms | ActiveRecord: 0.0ms)
Started GET "/stylesheets/graphiql/rails/application.css" for 10.242.2.16 at 2017-10-24 13:40:34 -0400
Processing by ApplicationController#routing_error as CSS
Parameters: {"path"=>"stylesheets/graphiql/rails/application"}
Route could not be found for GET /stylesheets/graphiql/rails/application.css
Completed 404 Not Found in 0.5ms (ActiveRecord: 0.0ms)
Started GET "/javascripts/graphiql/rails/application.js" for 10.242.2.16 at 2017-10-24 13:40:34 -0400
Processing by ApplicationController#routing_error as JS
Parameters: {"path"=>"javascripts/graphiql/rails/application"}
Route could not be found for GET /javascripts/graphiql/rails/application.js
Completed 404 Not Found in 0.2ms (ActiveRecord: 0.0ms)
I tried running rake assets:precompile
, and also tried copying the app/assets/ folder into my Rails app and then running rake assets:precompile
. These didn't have an effect. I also tried copying the javascripts/ and stylesheets folders into my app's public/ folder. This prevents the Route could not be found
error, but the page never loads. Should I try moving the whole engine into my app?
I'm constrained to use Rails 3.2 in this app, is that a known problem? I do have a minimal working graphql endpoint at /queries/admin, tested with curl. Any suggestions beyond those in issue #13?
Thanks!
I'm getting this error when running graphiql on my rails app. I'm following this tutorial. From what I've seen from other posts it probably means my Rails app is sending HTML and not JSON. But I'm not really clear why that's happening. Could someone clear up why this is happening?
Hi,
I'm getting this error when try to access to http://localhost:3000/graphiql
uninitialized constant GraphiQL::Rails::EditorsController
I've already installed graphql and graphiql gems
gem rails '5.1.6'
gem 'graphql', '1.7.4'
gem 'graphiql-rails', '1.4.10', group: :development
NOTE: I already try with 'graphiql-rails', '1.4.4' and it didn't work
The weird thing is that the classes Config Engine VERSION
have been loaded by not the EditorsController.
Seems that the problem is how the gem is requiring the rails embedded app.
I really appreciate your support to fix this issue.
Thanks
I am building a documentation server and would like to mount multiple GraphiQL that points to different GraphQL servers at once and use iframe to put it somewhere on my page. So in my routes.rb
, I did this
mount GraphiQL::Rails::Engine, at: "/server1/graphiql", graphql_path: 'http://server1/api/graphql'
mount GraphiQL::Rails::Engine, at: "/server2/graphiql", graphql_path: 'http://server2/api/graphql/'
But I got the following error,
/Users/lisaweng/.rbenv/versions/2.2.6/lib/ruby/gems/2.2.0/gems/actionpack-4.2.7.1/lib/action_dispatch/routing/route_set.rb:549:in `add_route': Invalid route name, already in use: 'graphiql_rails' (ArgumentError)
You may have defined two routes with the same name using the `:as` option, or you may be overriding a route already defined by a resource with the same naming. For the latter, you can restrict the routes created with `resources` as explained here:
http://guides.rubyonrails.org/routing.html#restricting-the-routes-created
Not sure if I did it wrong or is this not supported? Any help would be appreciated!
Is it possible to extend the toolbar as explained in https://github.com/graphql/graphiql#usage-examples ?
The end goal would be to be add a dropdown with some example queries. That when click would be added to the query window. Kind of like here graphql/graphiql#614
This looks just like a simple Rack app that you can mount in any Rack router. Does it work with sinatra / cuba / roda?
If you go to graphql.brandfolder.com and enter the following query, on reload it persists. This is a feature of the native graphIQL, would like to know why it isn't present in the rails version.
{
slug(uri: "brandfolder") {
id
}
}
Hi, thanks for this great gem!
I need to pass an authorisation header that comes from a different server with the request. Would you be open to a PR that configures the headerEditorEnabled
setting in graphiql?
Problem:
When running graphiql-rails and sprockets 4.0.0, accessing graphiql raises Sprockets::Rails::Helper::AssetNotPrecompiled in GraphiQL::Rails::Editors#show
Following the suggestion of
Asset `graphiql/rails/application.css` was not declared to be precompiled in production.
Declare links to your assets in `app/assets/config/manifest.js`.
//= link graphiql/rails/application.css
and restart your server
Doesn't seem to fix anything
I've reproduced the exception with a fresh rails app here: https://github.com/wesleyjellis/sprockets_graphql (Rails 6.0.0, sprockets 4.0.0, graphiql 1.7.0, ruby 2.6.3)
It's possible this is related to rails/sprockets#542 or rails/sprockets#415
Hi!
I'm using version 1.4.5 and I'm getting React errors:
Sadly, I don't know enough Rect to fix them, and the diff for v1.4.5 doesn't seem to modify many things:
So I cannot pinpoint where the error is. Can you help with that?
Thanks!
There is an error in the javascript when config.query_params is set to true that causes the interface to not load.
This line references onEditQuery which is not defined because the definition occurs within a different function scope.
Our graphiql interface stopped working suddenly and started throwing this error.
graphiql:5 Uncaught ReferenceError: ubd is not defined
at new n (application-9af39cd43435fa4995df6d33c71ce909f3dcde0e2af50842fd8470fa48bfb681.js:2)
at r (application-9af39cd43435fa4995df6d33c71ce909f3dcde0e2af50842fd8470fa48bfb681.js:2)
at f.value (application-9af39cd43435fa4995df6d33c71ce909f3dcde0e2af50842fd8470fa48bfb681.js:2)
at Object.M.handleRunQuery [as onRun] (application-9af39cd43435fa4995df6d33c71ce909f3dcde0e2af50842fd8470fa48bfb681.js:2)
at i._onClick (application-9af39cd43435fa4995df6d33c71ce909f3dcde0e2af50842fd8470fa48bfb681.js:2)
at HTMLUnknownElement.r (application-9af39cd43435fa4995df6d33c71ce909f3dcde0e2af50842fd8470fa48bfb681.js:2)
at HTMLUnknownElement.nrWrapper (graphiql:5)
at Object.ii (application-9af39cd43435fa4995df6d33c71ce909f3dcde0e2af50842fd8470fa48bfb681.js:2)
at Object.invokeGuardedCallback (application-9af39cd43435fa4995df6d33c71ce909f3dcde0e2af50842fd8470fa48bfb681.js:2)
at Object.invokeGuardedCallbackAndCatchFirstError (application-9af39cd43435fa4995df6d33c71ce909f3dcde0e2af50842fd8470fa48bfb681.js:2)
Everything works fine in development
I get this error after a fresh install:
ActionController::RoutingError (No route matches [GET] "/javascripts/graphiql/rails/application.js")
I'm setting up my first subscriptions using graphql-ruby
and ActionCable
. I'd like to be able to test out my implementation in graphiql
before proceeding with consuming the new subscription API in my relay frontend app, but from a scan of this repo it doesn't seem possible at this time.
PS Thanks for making this and graphql-ruby
. I could quickly get a graphql server in Rails thanks to these packages.
I have two environments configured in which I would like to use GraphiQL (my app behaives slightly differently in an enterprise mode than a development mode and have dev environments for both)
When loading the enterprise development environment I get the above error. GraphiQL should be capable of being mounted in any environment.
If you add GraphiQL Rails to pura Rails API app you will not get it working as assets are not accessible:
ActionController::RoutingError (No route matches [GET] "/stylesheets/graphiql/rails/application.css"):
ActionController::RoutingError (No route matches [GET] "/javascripts/graphiql/rails/application.js"):
I'm pretty sure this is API-only issue, documentation how to make it working should be improved
This looks pretty helpful. Any interest in integrating?
https://github.com/OneGraph/graphiql-explorer
Hello! I've attempted to set a header with the initializer:
# config/initializers/graphiql.rb
GraphiQL::Rails.config.headers["Authorization"] = -> (_context) { "here" }
My graphql endpoint looks like this:
# app/controllers/application_controller.rb
# omitting the rest of the file...
def graphql
puts "*"*50
puts request.headers["Authorization"]
puts "*"*50
end
Server log when sending the request via GraphiQL:
Started POST "/graphql" for ::1 at 2020-03-31 15:46:13 -0700
Processing by ApplicationController#graphql as */*
Parameters: {"query"=>"", "variables"=>"null", "operationName"=>nil, "application"=>{"query"=>"", "variables"=>"null", "operationName"=>nil}}
**************************************************
**************************************************
No template found for ApplicationController#graphql, rendering head :no_content
Do I need to invoke the config? Something else? The header is nil
. This is a new Rails app with the following versions:
Rails: 6.0.2.2
Ruby: 2.7.0
graphiql-rails: 1.7
I'm using csp headers and they are restricting to run inline scripts.
I made small changes and it removes inline script
onemanstartup@20f7647 - here I removed inline script and add csrf_meta_tag to get this value in js
onemanstartup@af152de (here I removed some options besides csrf token, because I'm not using this options yet and don't know how to better pass the data into script.
What do you think? Is this something worth doing?
I think is is also gives ability to embed graphiql in another view layer by requiring only one file.
Thanks <3
Using Rails 6.x and --api app I get the above error.
This Stackoverflow thread describes the issue.
https://stackoverflow.com/questions/58403931/the-action-execute-could-not-be-found-for-graphqlcontroller-when-using-graph
I'm encountering this issue #42 and I believe that the problem is due to using a rails 5 api only app.
Tried following these instructions #13 (comment) but they appear to be outdated.
Is there any way to make this gem work with an API app?
Hi @rmosolgo !
Thanks for your awesome job on GraphQL!
I'm trying to use GraphiQL rails with devise_token_auth
gem and with have the change_headers_on_each_request
option set to true. So i can't define the headers
in the initializer like this :
GraphiQL::Rails.config.headers.merge! User.first.create_new_auth_token
Where could i define this config to be refreshed on every request?
I got this when first open graphi page and failed to extend doc area but the query works fine.
Started POST "/queries" for 127.0.0.1 at 2016-10-15 16:10:34 +0800
Processing by QueriesController#create as */*
Parameters: {"query"=>"\n query IntrospectionQuery {\n __schema {\n queryType { name }\n mutationType { name }\n subscriptionType { name }\n types {\n ...FullType\n }\n directives {\n name\n description\n locations\n args {\n ...InputValue\n }\n }\n }\n }\n\n fragment FullType on __Type {\n kind\n name\n description\n fields(includeDeprecated: true) {\n name\n description\n args {\n ...InputValue\n }\n type {\n ...TypeRef\n }\n isDeprecated\n deprecationReason\n }\n inputFields {\n ...InputValue\n }\n interfaces {\n ...TypeRef\n }\n enumValues(includeDeprecated: true) {\n name\n description\n isDeprecated\n deprecationReason\n }\n possibleTypes {\n ...TypeRef\n }\n }\n\n fragment InputValue on __InputValue {\n name\n description\n type { ...TypeRef }\n defaultValue\n }\n\n fragment TypeRef on __Type {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n }\n }\n }\n }\n }\n }\n }\n }\n"}
Completed 500 Internal Server Error in 17ms
JSON::GeneratorError - only generation of JSON objects or arrays allowed:
json_pure (2.0.2) lib/json/common.rb:224:in `generate'
json_pure (2.0.2) lib/json/common.rb:224:in `generate'
json_pure (2.0.2) lib/json/common.rb:394:in `dump'
graphql (0.19.3) lib/graphql/introspection/input_value_type.rb:12:in `block (3 levels) in <top (required)>'
graphql (0.19.3) lib/graphql/field.rb:162:in `call'
graphql (0.19.3) lib/graphql/field.rb:162:in `resolve'
graphql (0.19.3) lib/graphql/query/serial_execution/field_resolution.rb:81:in `block in get_middleware_proc_from_field_resolve'
graphql (0.19.3) lib/graphql/schema/middleware_chain.rb:24:in `call'
graphql (0.19.3) lib/graphql/schema/middleware_chain.rb:24:in `call'
graphql (0.19.3) lib/graphql/schema/rescue_middleware.rb:34:in `call'
graphql (0.19.3) lib/graphql/schema/middleware_chain.rb:24:in `call'
graphql (0.19.3) lib/graphql/query/serial_execution/field_resolution.rb:69:in `get_raw_value'
graphql (0.19.3) lib/graphql/query/serial_execution/field_resolution.rb:18:in `result'
graphql (0.19.3) lib/graphql/query/serial_execution/selection_resolution.rb:22:in `block in result'
Hey Team,
I'm getting a Uncaught ReferenceError: ReactDOM is not defined
error when trying to load /graphiql
in my app. Hitting refresh fixes the problem. The issue occurs on multiple browsers and with extensions disabled.
I've tried updating to the latest gem versions.
...
graphiql-rails (1.4.10)
railties
sprockets-rails
graphql (1.7.13)
...
turbolinks (5.1.0)
turbolinks-source (~> 5.1)
turbolinks-source (5.1.0)
...
And the console error is
Uncaught ReferenceError: ReactDOM is not defined
at <anonymous>:33:5
at r.assignNewBody (turbolinks.self-2db6ec539b9190f75e1d477b305df53d12904d5cafdd47c7ffd91ba25cbec128.js?body=1:6)
at r.replaceBody (turbolinks.self-2db6ec539b9190f75e1d477b305df53d12904d5cafdd47c7ffd91ba25cbec128.js?body=1:6)
at turbolinks.self-2db6ec539b9190f75e1d477b305df53d12904d5cafdd47c7ffd91ba25cbec128.js?body=1:6
at r.e.renderView (turbolinks.self-2db6ec539b9190f75e1d477b305df53d12904d5cafdd47c7ffd91ba25cbec128.js?body=1:6)
at r.render (turbolinks.self-2db6ec539b9190f75e1d477b305df53d12904d5cafdd47c7ffd91ba25cbec128.js?body=1:6)
at Function.e.render (turbolinks.self-2db6ec539b9190f75e1d477b305df53d12904d5cafdd47c7ffd91ba25cbec128.js?body=1:6)
at t.renderSnapshot (turbolinks.self-2db6ec539b9190f75e1d477b305df53d12904d5cafdd47c7ffd91ba25cbec128.js?body=1:6)
at t.render (turbolinks.self-2db6ec539b9190f75e1d477b305df53d12904d5cafdd47c7ffd91ba25cbec128.js?body=1:6)
at e.render (turbolinks.self-2db6ec539b9190f75e1d477b305df53d12904d5cafdd47c7ffd91ba25cbec128.js?body=1:6)
(anonymous) @ VM231:33
r.assignNewBody @ turbolinks.self-2db6ec539b9190f75e1d477b305df53d12904d5cafdd47c7ffd91ba25cbec128.js?body=1:6
r.replaceBody @ turbolinks.self-2db6ec539b9190f75e1d477b305df53d12904d5cafdd47c7ffd91ba25cbec128.js?body=1:6
(anonymous) @ turbolinks.self-2db6ec539b9190f75e1d477b305df53d12904d5cafdd47c7ffd91ba25cbec128.js?body=1:6
e.renderView @ turbolinks.self-2db6ec539b9190f75e1d477b305df53d12904d5cafdd47c7ffd91ba25cbec128.js?body=1:6
r.render @ turbolinks.self-2db6ec539b9190f75e1d477b305df53d12904d5cafdd47c7ffd91ba25cbec128.js?body=1:6
e.render @ turbolinks.self-2db6ec539b9190f75e1d477b305df53d12904d5cafdd47c7ffd91ba25cbec128.js?body=1:6
t.renderSnapshot @ turbolinks.self-2db6ec539b9190f75e1d477b305df53d12904d5cafdd47c7ffd91ba25cbec128.js?body=1:6
t.render @ turbolinks.self-2db6ec539b9190f75e1d477b305df53d12904d5cafdd47c7ffd91ba25cbec128.js?body=1:6
e.render @ turbolinks.self-2db6ec539b9190f75e1d477b305df53d12904d5cafdd47c7ffd91ba25cbec128.js?body=1:6
(anonymous) @ turbolinks.self-2db6ec539b9190f75e1d477b305df53d12904d5cafdd47c7ffd91ba25cbec128.js?body=1:6
(anonymous) @ turbolinks.self-2db6ec539b9190f75e1d477b305df53d12904d5cafdd47c7ffd91ba25cbec128.js?body=1:6
requestAnimationFrame (async)
e.render @ turbolinks.self-2db6ec539b9190f75e1d477b305df53d12904d5cafdd47c7ffd91ba25cbec128.js?body=1:6
e.loadResponse @ turbolinks.self-2db6ec539b9190f75e1d477b305df53d12904d5cafdd47c7ffd91ba25cbec128.js?body=1:6
e.visitRequestCompleted @ turbolinks.self-2db6ec539b9190f75e1d477b305df53d12904d5cafdd47c7ffd91ba25cbec128.js?body=1:6
e.requestCompletedWithResponse @ turbolinks.self-2db6ec539b9190f75e1d477b305df53d12904d5cafdd47c7ffd91ba25cbec128.js?body=1:6
(anonymous) @ turbolinks.self-2db6ec539b9190f75e1d477b305df53d12904d5cafdd47c7ffd91ba25cbec128.js?body=1:6
e.endRequest @ turbolinks.self-2db6ec539b9190f75e1d477b305df53d12904d5cafdd47c7ffd91ba25cbec128.js?body=1:6
e.requestLoaded @ turbolinks.self-2db6ec539b9190f75e1d477b305df53d12904d5cafdd47c7ffd91ba25cbec128.js?body=1:6
(anonymous) @ turbolinks.self-2db6ec539b9190f75e1d477b305df53d12904d5cafdd47c7ffd91ba25cbec128.js?body=1:6
load (async)
e.createXHR @ turbolinks.self-2db6ec539b9190f75e1d477b305df53d12904d5cafdd47c7ffd91ba25cbec128.js?body=1:6
e @ turbolinks.self-2db6ec539b9190f75e1d477b305df53d12904d5cafdd47c7ffd91ba25cbec128.js?body=1:6
e.issueRequest @ turbolinks.self-2db6ec539b9190f75e1d477b305df53d12904d5cafdd47c7ffd91ba25cbec128.js?body=1:6
e.visitStarted @ turbolinks.self-2db6ec539b9190f75e1d477b305df53d12904d5cafdd47c7ffd91ba25cbec128.js?body=1:6
e.start @ turbolinks.self-2db6ec539b9190f75e1d477b305df53d12904d5cafdd47c7ffd91ba25cbec128.js?body=1:6
e.startVisit @ turbolinks.self-2db6ec539b9190f75e1d477b305df53d12904d5cafdd47c7ffd91ba25cbec128.js?body=1:7
e.startVisitToLocationWithAction @ turbolinks.self-2db6ec539b9190f75e1d477b305df53d12904d5cafdd47c7ffd91ba25cbec128.js?body=1:6
e.visitProposedToLocationWithAction @ turbolinks.self-2db6ec539b9190f75e1d477b305df53d12904d5cafdd47c7ffd91ba25cbec128.js?body=1:6
e.visit @ turbolinks.self-2db6ec539b9190f75e1d477b305df53d12904d5cafdd47c7ffd91ba25cbec128.js?body=1:6
e.clickBubbled @ turbolinks.self-2db6ec539b9190f75e1d477b305df53d12904d5cafdd47c7ffd91ba25cbec128.js?body=1:7
(anonymous) @ turbolinks.self-2db6ec539b9190f75e1d477b305df53d12904d5cafdd47c7ffd91ba25cbec128.js?body=1:6
Any suggestions for further troubleshooting?
Cheers Team!
Rails: 2.5.1
Ruby: 2.5.3
I dont know why am receiving this kind of error because it was said fix in latest graphiql update
graphql/graphiql@7764ba5.
What is the purpose of the Docs sidebar in GraphiQL? It doesn't seem to do anything, only show a loading indicator when I click the button that opens it.
I decided to break my resolver functions out into actual Resolver classes (in an app/graphql/resolvers
directory), mainly because my app is already pretty big and having all of the field definitions and resolver functions in my QueryType class was getting unruly and the problem was only going to get worse as our product grows.
All my request specs pass just like before I broke them out, and it all seems to be working fine on our dev app on Heroku, both querying GraphQL directly and when using the GraphiQL playground.
However, I noticed that I'm getting this error when I try to play with it in GraphiQL on local, but only in some cases, and it seems not consistently:
uninitialized constant Resolvers::MyResolver::MyModel
An example:
A Recipient
belongs to an Organization
My base Resolver:
class Resolvers::Base < GraphQL::Schema::Resolver
def authorize_resource(resource, action)
return if Pundit.policy(context[:current_user], resource).send("#{action}?")
raise GraphQL::ExecutionError, "Unauthorized: #{action} #{resource}"
end
end
A problematic Resolver:
class Resolvers::Questions < Resolvers::Base
type [QuestionType], null: false
argument :organization_uuid, ID, required: false
def resolve(organization_uuid: nil)
user = context[:current_user]
organization = Organization.friendly.find(organization_uuid) if organization_uuid
if organization.present?
authorize_resource(organization, 'show')
organization.questions
else
Question.where(organization_uuid: user.organization_uuids)
end
end
end
When I run the query:
query {
questions(organizationUuid: "14afb4cc-3ab8-11e9-b185-186590df942f") {
uuid
}
}
It works. However, when I run it without scoping it to a specific organization, ie:
query {
questions {
uuid
}
}
I get the error uninitialized constant Resolvers::Questions::Question
.
Why would the Organization model be loaded just fine but not the Question model? It seems like it's looking for the model inside the existing class in the Question case, but looking outside of it (and finding it succesfully) in the Organization case. Some Resolvers seem to work just fine with zero problems.
I tried tweaking the autoload_paths
in config/application.rb
but haven't had any success yet. I read that Rails handles autoloading different in production vs local and that messing with it is risky, anyway. That said, I have my types folder added. When I tried added my resolvers folder, there were all sorts of errors.
Here is my autoload paths list:
.../app/graphql/types
.../app/assets
.../app/channels
.../app/controllers
.../app/controllers/concerns
.../app/graphql
.../app/helpers
.../app/javascript
.../app/jobs
.../app/mailers
.../app/models
.../app/models/concerns
.../app/observers
.../app/policies
Any help is appreciated.
I have been trying to use this version of graphiql-rails
with graphql
version 1.9.3, which gave me the below response. When I ported back to 1.18.0, the proper response came through. I apologize that I can't make a PR myself to resolve this at the moment, since I'm a total n00b to GraphQL, but I wanted to make you aware for your next release.
Big fan of the tool, so thank you for the work y'all have done!
Michael
class Types::MutationType < GraphQL::Schema::Object
field :updateUser, mutation: Mutations::UpdateUser
end
class Mutations::UpdateUser < Mutations::BaseMutation
argument :id, ID, required: true
argument :name, String, required: false
argument :title, String, required: false
argument :role, Int, required: false
field :user, Types::UserType, null: true
field :errors, [String], null: false
def resolve( id:, name:, title:, role:)
user = User.find(id)
if user.update(name: name, title: title, role: role)
{
user: user,
errors: []
}
else
{
user: nil,
errors: []
}
end
end
end
mutation updateUser($id: ID!, $name: String, $title: String, $role: Int) {
updateUser(id:$id, name: $name, title: $title, role:$role) {
user {
name
id
}
}
}
// Query Values
{
"id": 1,
"name": "Mr. Smith",
"title": "President",
"role": 3
}
{
"data": {
"updateUser": {
null
}
}
}
I don't see any updates since January 2019. There are many open, unanswered issues.
I don't fault the owner for abandoning it, and I fully acknowledge that maintaining open source is difficult. I'd just like to know if there are any plans to update this, or should we consider looking for alternate solutions elsewhere.
Is there a way to default or pass context variables thru graphiql-rails interface?
Would much prefer this gem used the following project instead:
https://github.com/OlegIlyenko/graphiql-workspace
Or at least a guide or something on how to do it...
Hi, thanks for a great project!
graphiql seems to work fine in rails 6.1 without the sass gem - is this new in 6.1 vs 6, or is the readme wrong, or am i mistaken because something is maybe cached?
these two seem to be generated just fine
/assets/graphiql/rails/application-...js
/assets/graphiql/rails/application-...css
Beginning with version 1.5.0 of this gem the GraphiQL frontend does not load in production environments. Chrome console output:
application-62bfd22d15244d19e3fe71894ec33a25361eac62e7b985cf9206122d51a6e0ae.js:22 Uncaught Error: Cannot use t "__Schema" from another module or realm.
Ensure that there is only one instance of "graphql" in the node_modules
directory. If different versions of "graphql" are the dependencies of other
relied on modules, use "resolutions" to ensure only one version is installed.
https://yarnpkg.com/en/docs/selective-version-resolutions
Duplicate "graphql" modules cannot be used at the same time since different
versions may have different capabilities and behavior. The data from one
version used in the function from another could produce confusing and
spurious results.
at i (application-62bfd22d15244d19e3fe71894ec33a25361eac62e7b985cf9206122d51a6e0ae.js:22)
....
graphiql:45 Uncaught ReferenceError: GraphiQL is not defined
at graphiql:45
Tested with an empty Rails 5.1.4 app.
Any idea why or what? I'm not a react/node/js guy ๐
There is currently no ability to pass headers--since bearer token/JWT is fairly common this makes using this library pretty difficult.
I'm going to fool around with merging this library into this one because it's a joy to use:
https://github.com/OlegIlyenko/graphiql-workspace
Would you be open to something like that, or at a minimum adding header support?
is there a way to hook into the GET route and redirect if there is no auth token / cookie?
Hi, I am just getting started with GraphQL.
$ bundle add graphql graphiql-rails
Which added:
gem "graphql", "~> 1.11"
gem "graphiql-rails", "~> 1.7"
to Gemfile
$ rails g graphql:install
//= link graphiql/rails/application.css
//= link graphiql/rails/application.js
Rails.application.routes.draw do
if Rails.env.development?
mount GraphiQL::Rails::Engine, at: '/graphiql', graphql_path: '/graphql'
end
end
rails s -b 0 -p 8080
Hi. I am trying to upgrade rails from 6.1 to 7.0.2, and I have an issue with this gem on the new version:
ActionView::Template::Error (Your application has sessions disabled. To write to the session you must first configure a session store):
11: graphql_endpoint_path: graphql_endpoint_path,
12: initial_query: GraphiQL::Rails.config.initial_query,
13: logo: GraphiQL::Rails.config.logo,
14: headers: GraphiQL::Rails.config.resolve_headers(self),
15: query_params: GraphiQL::Rails.config.query_params
16: } %>
17: </body>
actionpack (7.0.2.3) lib/action_dispatch/request/session.rb:253:in `load_for_write!'
actionpack (7.0.2.3) lib/action_dispatch/request/session.rb:151:in `[]='
actionpack (7.0.2.3) lib/action_controller/metal/request_forgery_protection.rb:449:in `real_csrf_token'
actionpack (7.0.2.3) lib/action_controller/metal/request_forgery_protection.rb:467:in `csrf_token_hmac'
actionpack (7.0.2.3) lib/action_controller/metal/request_forgery_protection.rb:461:in `global_csrf_token'
actionpack (7.0.2.3) lib/action_controller/metal/request_forgery_protection.rb:370:in `masked_authenticity_token'
actionpack (7.0.2.3) lib/action_controller/metal/request_forgery_protection.rb:357:in `form_authenticity_token'
actionpack (7.0.2.3) lib/action_controller/metal/request_forgery_protection.rb:107:in `form_authenticity_token'
graphiql-rails (1.8.0) lib/graphiql/rails/config.rb:17:in `block in <class:Config>'
graphiql-rails (1.8.0) lib/graphiql/rails/config.rb:38:in `block in resolve_headers'
graphiql-rails (1.8.0) lib/graphiql/rails/config.rb:37:in `each'
graphiql-rails (1.8.0) lib/graphiql/rails/config.rb:37:in `each_with_object'
graphiql-rails (1.8.0) lib/graphiql/rails/config.rb:37:in `resolve_headers'
graphiql-rails (1.8.0) app/views/graphiql/rails/editors/show.html.erb:14
Tried pretty much everything I was able to find online (not too many things out there tho). Did anyone see this issue before or any ideas on how to make it work?
Related versions:
ruby 2.7.4
rails 7.0.2.3
graphql 2.0.2
graphiql-rails 1.8.0
Can anyoner explain what should be the path?
# config/routes.rb
Rails.application.routes.draw do
# ...
if Rails.env.development?
mount GraphiQL::Rails::Engine, at: "/graphiql", graphql_path: "/your/endpoint"
end
end
In case we want to use an http verb other than POST
, it'd be useful to be able to specify it when we mount the engine. Something like:
mount GraphiQL::Rails::Engine, at: "/graphiql", graphql_path: "/graph", method: :get
If you thing this is useful, I can work on the change.
Thanks.
After rails g graphql:install
, accessing the view raises this in development
:
Started GET "/graphiql" for 172.19.0.1 at 2020-01-19 01:45:59 +0000
Processing by GraphiQL::Rails::EditorsController#show as HTML
Parameters: {"graphql_path"=>"/graphql"}
Rendering /usr/local/bundle/gems/graphiql-rails-1.7.0views/graphiql/rails/editors/show.html.erb
Rendered /usr/local/bundle/gems/graphiql-rails-1.7.0views/graphiql/rails/editors/show.html.erb (Duration: 171.3ms | Allocations: 4865)
Completed 500 Internal Server Error in 211ms (ActiveRecord: 0.0ms | Allocations: 6087)
I'm having a hard time figuring out the stack trace. Will post back when I get to it.
Any ideas in the mean time?
I've actually not seen this kind of issue before, and I'm unsure how it's happening and what the implications are at a higher level, but it's keeping things from loading.
I've a very basic and simple implementation at the moment, and am just starting out with the graphql toolset.
I start the rails server in the development environment (default) and browse to the mounted engine at graphiql
and see "Loading..." in the DOM and the following in the console:
Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self' https: 'unsafe-eval'". Either the 'unsafe-inline' keyword, a hash ('sha256-OncdEJD4oqeHhZYWbJ3+w14Ptu8kMNYBli6LjYjVZRs='), or a nonce ('nonce-...') is required to enable inline execution.
It seems like the problem stems from the opening script
tag. I'm using Rails 5.2.1.
Here's some more reading: https://developers.google.com/web/fundamentals/security/csp/
We are using graphiql-rails as a dependency on one our gems.
From version 1.5
the graphiql page is broken. I can confirm that 1.4.11
along with graphql 1.8.10
works.
The error is present only in production environment. Development works. Might be something that happens during the assets precompile process.
Accessing GraphiQL page I see only the loading...
message and get this error:
Uncaught Error: Cannot use t "__Schema" from another module or realm.
Ensure that there is only one instance of "graphql" in the node_modules
directory. If different versions of "graphql" are the dependencies of other
relied on modules, use "resolutions" to ensure only one version is installed.
https://yarnpkg.com/en/docs/selective-version-resolutions
Duplicate "graphql" modules cannot be used at the same time since different
versions may have different capabilities and behavior. The data from one
version used in the function from another could produce confusing and
spurious results.
Which then create a second obvious error:
Uncaught ReferenceError: GraphiQL is not defined
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.