Skip to content

Commit

Permalink
feat: add preAuthLinks option, closes #86 (#243)
Browse files Browse the repository at this point in the history
  • Loading branch information
matrunchyk authored Jun 8, 2020
1 parent 32e7db2 commit d6aa49e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions docs/guide/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ createApolloClient({
// Custom starting link.
// If you want to replace the default HttpLink, set `defaultHttpLink` to false
link: null,
// Custom pre-auth links
// Useful if you want, for example, to set a custom middleware for refreshing an access token.
preAuthLinks: [],
// If true, add the default HttpLink.
// Disable it if you want to replace it with a terminating link using `link` option.
defaultHttpLink: true,
Expand Down
7 changes: 7 additions & 0 deletions graphql-client/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ export function createApolloClient ({
// Custom starting link.
// If you want to replace the default HttpLink, set `defaultHttpLink` to false
link = null,
// Custom pre-auth links
// Useful if you want, for example, to set a custom middleware for refreshing an access token.
preAuthLinks = [],
// If true, add the default HttpLink.
// Disable it if you want to replace it with a terminating link using `link` option.
defaultHttpLink = true,
Expand Down Expand Up @@ -85,6 +88,10 @@ export function createApolloClient ({

// Concat all the http link parts
link = authLink.concat(link)

if (preAuthLinks.length) {
link = from(preAuthLinks).concat(authLink)
}
}

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

0 comments on commit d6aa49e

Please sign in to comment.