-
Notifications
You must be signed in to change notification settings - Fork 253
How to use this gem with graphql gem? #194
Comments
You can include the class GraphqlController < ActionController::Base
include Knock::Authenticable
before_action :authenticate
def execute
# snip...
context = {
# Query context - +current_user+ is available when authenticated:
current_user: current_user,
}
# snip...
render json: result
end
end For running queries in Graphiql, I’m currently using https://github.com/skevy/graphiql-app so that I can add the Bearer token to an Authentication header (adding custom request headers isn’t currently supported in the main graphiql tool). |
And what if I have some query for unauthenticated people?
|
@christopherstyles This is totally great. One question - I need to have some GraphQL mutations (createUser, signIn) skip authentication. I'm wondering if it would be better to:
If you have thoughts on this, I would dearly love to hear them! 🥇 |
@sterrym Have you ever figured out how to do this? If so, how? |
@matejLukasik Unfortunately (for this thread), we ended up going a different direction on the app we were working on and didn't use the knock gem at all. We ended up doing unauthenticated calls as regular API calls which created the JWT for us using the devise-jwt gem (https://github.com/waiting-for-dev/devise-jwt). If I were doing it now, I might stick with knock but I think I'd still implement the unauthenticated calls outside of GraphQL. That being said, I'm seeing 53 issues in this gem dating back to 2016 and the last commit 2 years ago. All that doesn't really bode well for this gem being maintained... |
Hello! I'm also facing this issue:
Is there any way to allow certain mutations to be executed by unauthenticated users? |
How to use this gem with graphql gem?
The text was updated successfully, but these errors were encountered: