Skip to content
This repository has been archived by the owner on Apr 14, 2023. It is now read-only.

Feature Request: Transform Request before sending #257

Closed
steffenmllr opened this issue Nov 17, 2017 · 4 comments
Closed

Feature Request: Transform Request before sending #257

steffenmllr opened this issue Nov 17, 2017 · 4 comments

Comments

@steffenmllr
Copy link

I'm trying to implement hawk authentication for my graphql endpoint. For this I need access to the request options and update the Authorization Headers.

Currently there is no way to access / update the data before the request is happening. Would be nice if there were. Since I need the actual request (including the final payload) to calculate the Headers a middlewareLink doesn't seem to work.

@jbaxleyiii
Copy link
Contributor

@steffenmllr whoa! I've never seen that before!

Yeah I think this would be a great addition to the http-link package. It would also allow quite a lot of other features. Would you be up for a PR to add this?

I'd be happy to help you, or anyone else who wants to add this in!

@jbaxleyiii
Copy link
Contributor

@steffenmllr so this is actually already possible! I'll push a test showing it soon!

@steffenmllr
Copy link
Author

@jbaxleyiii great news! I just monkey patched the link package for now which works but a offical version would be great

@jbaxleyiii
Copy link
Contributor

@steffenmllr so you can pass a custom fetch to the link which allows you to intercept the request and modify it as needed when you need the fully formed request:

const customFetch = (uri, options) => {
  const { header } = Hawk.client.header('http://example.com:8000/resource/1?b=1&a=2', 'GET', { credentials: credentials, ext: 'some-app-data' });
  options.headers.Authorization = header;
  return fetch(uri, options);
};

const link = createHttpLink({ fetch: customFetch });

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants