Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying to access /graphql#execute app claims action could not be found #21

Closed
aarona opened this issue Oct 15, 2019 · 3 comments
Closed

Comments

@aarona
Copy link
Contributor

aarona commented Oct 15, 2019

Here is my routes.rb:

Rails.application.routes.draw do
  post "/graphql", to: "graphql#execute" 
  mount_graphql_devise_for 'User'
 
  #Do not place any routes below this one
  if Rails.env.production?
    get '*other', to: 'static#index'
  end
end

Here is my rake routes output:

prompt> rake routes | grep graphql
     graphql POST   /graphql(.:format)       graphql#execute
graphql_auth POST   /graphql_auth(.:format)  graphql_devise/graphql#auth
             GET    /graphql_auth(.:format)  graphql_devise/graphql#auth

Now we I go to http://localhost:3000/graphql I get the following server error:

Started POST "/graphql" for 127.0.0.1 at 2019-10-14 17:25:41 -0700

AbstractController::ActionNotFound (The action 'execute' could not be found for GraphqlController):
  
actionpack (6.0.0) lib/abstract_controller/base.rb:131:in `process'
(stack track continues)...

Any idea what I could be doing wrong? Meanwhile, I'm going to play with the dummy app and see if it works for me.

@mcelicalderon
Copy link
Member

Hey @aarona looks like this might be unrelated to the gem. As you can see on your routes output, the gem uses the auth action on our own graphql_devise/graphql controller. How you mount your own graphql schema is a different story. For that, you should follow the graphql gem instructions and run the generator in your app. Looks like your own personal graphql controller is missing the action execute which should process que request using your own graphql schema. Look how the dummy app does it in the routes and controller

@aarona
Copy link
Contributor Author

aarona commented Oct 15, 2019

You're right. I figured out how I got to this issue. I'm using the GraphiQL application to hit localhost:3000/graphql_auth and it was just hanging/spinning (which should be the issue you'd be concerned with) and figured that this was related. I do have an execute action though:

class GraphqlController < ApplicationController
  # If accessing from outside this domain, nullify the session
  # This allows for outside API access while preventing CSRF attacks,
  # but you'll have to authenticate your user separately
  protect_from_forgery with: :null_session

  def execute
    variables = ensure_hash(params[:variables])
    query = params[:query]
    operation_name = params[:operationName]
    context = {
      # Query context goes here, for example:
      # current_user: current_user,
    }
    result = JwtRailsExampleSchema.execute(query, variables: variables, context: context, operation_name: operation_name)
    render json: result
  rescue => e
    raise e unless Rails.env.development?
    handle_error_in_development e
  end
...
end

My graphql_auth route is working now for some reason so I'll have to figure out what else is going on with my project. Thanks!

@aarona aarona closed this as completed Oct 15, 2019
@aarona
Copy link
Contributor Author

aarona commented Oct 16, 2019

Ok after some research it looks like its because I'm using the create-repack-app which creates an API only rails app. This line in execute:

protect_from_forgery with: :null_session

is causing the problem. Are you guys using API only rails apps when testing? I wonder what I should do about this? I think I can just delete that line if I use CORS and graphql_devise for authentication, right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants