This repository was archived by the owner on Jul 3, 2024. It is now read-only.
Allow custom fetch on mutations (small PR)#34
Open
scottBowles wants to merge 1 commit intoleveluptuts:mainfrom
Open
Allow custom fetch on mutations (small PR)#34scottBowles wants to merge 1 commit intoleveluptuts:mainfrom
scottBowles wants to merge 1 commit intoleveluptuts:mainfrom
Conversation
|
Contributor
|
Good call but I think I have something different in mind to solve this. Will update soon. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Currently, queries accept a custom fetch (mainly for SvelteKit's SSR fetch) but mutations use the browser's fetch, since they will always have access to it. This PR will allow the developer to pass a custom
fetchto both.Why?
For those of us using external apis and needing to add an Authorization header to the request. Like the SvelteKit RealWorld example app, I store a jwt in a cookie, receive the cookie in the
handlehook, and put the jwt in thesession. In order to hit the external api directly with gQuery rather than routing everything through a SvelteKit endpoint, it makes sense to retrieve the token from the session store whenever I need to hit the api. Given access to the fetch function, I can easily wrapfetchand add the token to the Authorization header. But gQuery's current implementation doesn't allow for this on mutations since I have no access to thefetchfunction being used.