nearform / graphql-hooks

🎣 Minimal hooks-first GraphQL client
Other
1.88k stars 90 forks source link

feat(graphql-hooks): add headers to client response #1186

Closed madshall closed 3 months ago

madshall commented 3 months ago

What does this PR do?

This PR adds headers to client response. So along with data, graphQLErrors, httpErrors etc there will be response headers as well. Sometimes response headers contain useful info that the client might need to access. Currently the only way to access them is from responseReducer because it gets passed the entire response before generateResult is called on it. That doesn't scale well because it needs to be set on every single query which leads to repetitive code and lack of unification. One of the use cases for when the response headers are needed is logging middleware:

Let me know if you want me to update the documentation. Didn't do that initially because some teams prefer to do it themselves.

Related issues

https://github.com/nearform/graphql-hooks/issues/1192

Checklist

netlify[bot] commented 3 months ago

Deploy request for graphql-hooks-cra pending review.

Visit the deploys page to approve it

Name Link
Latest commit 72a7302dd4a5bef1a9c7bb4fdaf39df1da5c9d77
github-actions[bot] commented 3 months ago

No linked issues found. Please add the corresponding issues in the pull request description.
Use GitHub automation to close the issue when a PR is merged

floridemai commented 3 months ago

@madshall Thanks for working on this 🙇 Also I've noted a colon at the end of the last property of an object which wasn't there before. Maybe run an prettier before? It will probably affect other files - up to you if you want to commit those too.

In regards to the docs, I think you should go ahead and update that as well. Appreciate it.

The code looks good to me so far. Thank you!

madshall commented 3 months ago

@floridemai I've created the issue to reference here, updated the docs and removed the extra colons. Thank you!

madshall commented 3 months ago

Hi @simoneb, when can this be published to npm?

simoneb commented 3 months ago

Done