apollo-datasource-http icon indicating copy to clipboard operation
apollo-datasource-http copied to clipboard

[QUESTION]: onRequest and query

Open simplecommerce opened this issue 2 years ago • 2 comments

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.

simplecommerce avatar Mar 08 '22 16:03 simplecommerce

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 avatar Mar 20 '22 06:03 llc1123

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.

llc1123 avatar Apr 17 '22 13:04 llc1123