rmosolgo / graphiql-rails

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

ActionController::RoutingError: No route matches [POST] \"/graphql\" #45

Closed leosoaivan closed 6 years ago

leosoaivan commented 6 years ago

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.

leosoaivan commented 6 years ago

Figured it out. It seems the post route shouldn't have been nested. Closing!

Jorge-Ortiz-Mata commented 1 year ago

I'm getting the same error. Can you tell me what solved the problem? These are my routes:

Rails.application.routes.draw do
  if Rails.env.development?
    mount GraphiQL::Rails::Engine, at: "/graphiql", graphql_path: "/graphql"
  end
  post "/graphql", to: "graphql#execute"
  # Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html

  # Defines the root path route ("/")
  # root "articles#index"
end
fitzfoufou commented 1 year ago

Having same issue here in dev mode than @Jorge-Ortiz-Mata