ohler55 / agoo

A High Performance HTTP Server for Ruby
MIT License
912 stars 39 forks source link

Changes on args or req does not get fowarded to the other calls #112

Closed Marcoshsc closed 2 years ago

Marcoshsc commented 2 years ago

Hello, my name is Marcos, and I'm using Agoo with graphql on the company's project. I'm trying to intercept graphql queries and mutations in order to authorize the user before the actual calls are made (basically a middleware). I'm doing this on the query and mutation methods like the following: image Queries::Query.new has all the queries available on the schema, and Mutations::Mutation.new has all the available mutations. As you can see I'm storing the logged user in the received args and also tried to store on the request headers. However, when I'm inside the individual queries, this changes are not fowarded, since the args does not have the LOGGED_USER property anymore, neither the request header LOGGED_USER that I put. If I log the args value before the Queries::Query.new or Mutations::Mutation.new, the LOGGED_USER is present, however on the individual calls it seems that the changes are not being fowarded.

Is there a way that we can foward this changes to the individual queries?

ohler55 commented 2 years ago

I did expect that the req would be propagated so let me check to see why they aren't.

ohler55 commented 2 years ago

I see the issue. You will not be able to add to the headers but with a change I'll make tonight you should be able to add data to the request (req).

ohler55 commented 2 years ago

Easier than I expected. Please try the deny-introspection branch. Use req.set('LOGGED_USER', user) and the field will be in the req.env['LOGGED_USER'].

ohler55 commented 2 years ago

Released v2.15.1 with the fixes.

Marcoshsc commented 2 years ago

Hi @ohler55, thank you for making the changes. I tried the request here, but for some reason I got a segmentation fault :(. I will post below my ruby code and also the terminal output with the segmentation fault. When the error occurs, the app goes down immediately. My code: image The error is attached on a terminal.txt file. Thank you for your time in advance. terminal.txt

ohler55 commented 2 years ago

I haven't tested yet but I think I know the issue. Feel free to try branch request-set-fix. I'll test it later tonight.

ohler55 commented 2 years ago

okay, tested. Please let me know if it works for you as well.

Marcoshsc commented 2 years ago

Hi @ohler55, now everything is working. Just let me know when you create a new production release so I can update here on my project. Thank you for your time.

ohler55 commented 2 years ago

Released v2.15.2