rmosolgo / graphiql-rails

Mount the GraphiQL query editor in a Rails app
MIT License
447 stars 135 forks source link

Possible to mount multiple GraphiQL at once? #19

Closed mumuWeng closed 7 years ago

mumuWeng commented 7 years ago

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!

rmosolgo commented 7 years ago

Wow, I never thought of this!

It looks like it might be possible, see this stack overflow response for using the as option:

http://stackoverflow.com/a/33419438/1741654

You could try the same thing here. For example:

mount GraphiQL::Rails::Engine, as: "graphiql_1", at: "/server1/graphiql", graphql_path: 'http://server1/api/graphql'
mount GraphiQL::Rails::Engine, as: "graphiql_2", at: "/server2/graphiql", graphql_path: 'http://server2/api/graphql/'

Could you give that a try? Let me know what you find!

mumuWeng commented 7 years ago

Works like a charm! Thanks for the help 😄