Skip to content

Commit d6aa49e

Browse files
authored
feat: add preAuthLinks option, closes #86 (#243)
1 parent 32e7db2 commit d6aa49e

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

docs/guide/configuration.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ createApolloClient({
2626
// Custom starting link.
2727
// If you want to replace the default HttpLink, set `defaultHttpLink` to false
2828
link: null,
29+
// Custom pre-auth links
30+
// Useful if you want, for example, to set a custom middleware for refreshing an access token.
31+
preAuthLinks: [],
2932
// If true, add the default HttpLink.
3033
// Disable it if you want to replace it with a terminating link using `link` option.
3134
defaultHttpLink: true,

graphql-client/src/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ export function createApolloClient ({
2929
// Custom starting link.
3030
// If you want to replace the default HttpLink, set `defaultHttpLink` to false
3131
link = null,
32+
// Custom pre-auth links
33+
// Useful if you want, for example, to set a custom middleware for refreshing an access token.
34+
preAuthLinks = [],
3235
// If true, add the default HttpLink.
3336
// Disable it if you want to replace it with a terminating link using `link` option.
3437
defaultHttpLink = true,
@@ -85,6 +88,10 @@ export function createApolloClient ({
8588

8689
// Concat all the http link parts
8790
link = authLink.concat(link)
91+
92+
if (preAuthLinks.length) {
93+
link = from(preAuthLinks).concat(authLink)
94+
}
8895
}
8996

9097
// On the server, we don't want WebSockets and Upload links

0 commit comments

Comments
 (0)