Search code examples
ruby-on-railsrubygraphql-rubygraphiql

grapgql-ruby using the graphiql interface on a Rails 5 api


This is probably something stupid simple, but not sure how to run the graphiql interface when working with a rails api. Possible this might not be feasible as when i installed the gem, it made reference to not installing graphiql i believe because it detected i was using a api. I did tho manually install the gem:

  gem 'graphiql-rails', '1.4.4'

thanks in advance


Solution

  • you only need agree this gem https://github.com/rmosolgo/graphql-ruby and add the next code in routes.rb

    if Rails.env.development?
      mount GraphiQL::Rails::Engine, at: "/graphiql", graphql_path: "/graphql"
    end
    

    and to auto load the types need agree this

    config.autoload_paths << Rails.root.join('graphql', 'types')
    

    after that, run rails s and on 0:0:0:0:3000/graphiql should be show the interface