StarpTech / apollo-datasource-http

Optimized JSON HTTP Data Source for Apollo Server
MIT License
73 stars 32 forks source link

[QUESTION]: onRequest and query #31

Open simplecommerce opened 2 years ago

simplecommerce commented 2 years ago

Hi,

I had a question in regards to this library. In some cases I need to pass an authentication or query param that I need to fetch from another source. I tried to pass that in the request.query and I noticed that it does not get added to the path since the build query is done prior to calling onRequest.

Is this intended behavior?

How do you guys handle such scenarios? I just want to make sure I am using it properly.

llc1123 commented 2 years ago

You should manipulate request.path directly in onRequest. In my situation, to sign the query string with a function:

  protected async onRequest(request: Request): Promise<void> {
    request.path = request.path.split('?')[0] + '?' + sign(request.query)
  }
llc1123 commented 2 years ago

I have made the argument of onRequest to be Dispatcher.RequestOptions which doesn't include query field. User will have no access to request.query and have to manipulate the query string in request.path. It should avoid this issue happen in the future.