You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
How would you authorize in Rails?(Assuming you set context: current_user properly in app/channels/graphql_channel.rb) I'm trying to update users when a friend request has been received.
So far it works. Only drawback: authorization. Currently, the client puts in a user_id to specify which user's content to subscribe to, but any user can pass in any other user's id. Instead, I want each subscription to subscribe using ctx[:current_user].id. But idk how to access the context. How would I do this? I tried adding a call(obj, args, ctx) or resolve method to my subscription, but it didn't work. Here's what I've got for reference:
A subscription for newly received friend requests:
# app/graphql/subscriptions/friend_request_received.rbclassSubscriptions::FriendRequestReceived < GraphQL::Functiontype !Types::FriendRequestTypeargument:id, !types.IDdescription'A friend request was received by the user.'end
# app/models/friend_request.rbclassFriendRequest < ApplicationRecordafter_create:update_subscribers
...
defupdate_subscribersCreateFriendRequestJob.new(self).enqueueend
...
end
Let me know if anyone can help in any way! Also, does this make sense? I'm doing all of my work for the subscription OUTSIDE of the subscription file itself, which kind of feels weird. Is this the proper way to do things? Thanks!
The text was updated successfully, but these errors were encountered:
or, you can bundle master with gem "graphql", github: "rmosolgo/graphql-ruby" in your Gemfile. Please reopen this if it doesn't work for you, and 👏 again for @flyfy1's work on this topic!
How would you authorize in Rails? (Assuming you set
context: current_user
properly inapp/channels/graphql_channel.rb
) I'm trying to update users when a friend request has been received.<-- Edit: Can scope help me? -- >
<-- Edit: It's similar to #1057 -->
So far it works. Only drawback: authorization. Currently, the client puts in a user_id to specify which user's content to subscribe to, but any user can pass in any other user's id. Instead, I want each subscription to subscribe using
ctx[:current_user].id
. But idk how to access the context. How would I do this? I tried adding acall(obj, args, ctx)
orresolve
method to my subscription, but it didn't work. Here's what I've got for reference:A subscription for newly received friend requests:
A job that triggers all subscribers:
A method creates a job after_create:
Let me know if anyone can help in any way! Also, does this make sense? I'm doing all of my work for the subscription OUTSIDE of the subscription file itself, which kind of feels weird. Is this the proper way to do things? Thanks!
The text was updated successfully, but these errors were encountered: