Search code examples
ruby-on-railsgraphqlruby-on-rails-6graphiql

Rails 6 API mode GraphiQL shows 404?


I have a rails 6 app in api mode and I'm implementing a v2 of the api to include graphQL. I can make queries in postman just fine but when I goto http://localhost:5000/api/v2/graphiql/ I get the pretty interface but all my queries return a 404 like so:

"status": 404, "error": "Not Found", "exception": "#<ActionController::RoutingError: uninitialized constant GraphqlController>",

Have I done something wrong in my routes or is it something else?

Rails.application.routes.draw do
  
  namespace :api do
    namespace :v1 do
      resources :locations
    end
    namespace :v2 do

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

      end

      post "/graphql", to: "graphql#execute"

    end
  end
end

Solution

  • So with the help of a friend I realized the mistake. To fix this here issue you just change graphql_path: "/graphql" to the actual path. So in my case it was "/api/v2/graphql/"