-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: rm nested 'links' dir, raise links into apolloLinks/
- Loading branch information
1 parent
8cb288a
commit 40cf65f
Showing
7 changed files
with
33 additions
and
35 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,41 @@ | ||
import { ApolloLink } from "@apollo/client/link/core"; | ||
import { | ||
apiHttpLink, | ||
errorLink, | ||
getAuthTokenLink, | ||
// loggerLink, | ||
retryLink, | ||
} from "./links"; | ||
|
||
// TODO add apollo-link-rest and delete httpService & authService | ||
import { apiHttpLink } from "./link.apiHttp"; | ||
import { errorLink } from "./link.error"; | ||
import { getAuthTokenLink } from "./link.getAuthToken"; | ||
import { retryLink } from "./link.retry"; | ||
|
||
/** | ||
* This is the Apollo Link that is used to make all requests to the server. | ||
* | ||
* **Link Process Outline:** `(1, 2, 3, 4, 5 => SERVER => 5, 4, 3, 2, 1)` | ||
* | ||
* **Links:** | ||
* | ||
* 1. loggerLink | ||
* - Only imported and used in dev mode | ||
* - Logs all requests and responses | ||
* | ||
* 2. getAuthTokenLink | ||
* - Sets Authorization header (value will be null if !token) | ||
* | ||
* 3. retryLink | ||
* - Catches and retries _NETWORK_ errors | ||
* - _Does not catch/retry GraphQL errors_ | ||
* | ||
* 4. errorLink | ||
* - Logs network errors _AND_ GraphQL errors | ||
* - Catches and retries _GraphQL_ errors | ||
* - When AuthenticationError is thrown on the server, that comes back as a | ||
* _GraphQL_ error which can not be caught by the `retryLink`, so this link | ||
* handles sending the retry-request to the `/auth/token` endpoint. | ||
* | ||
* 5. apiHttpLink | ||
* - Sends request to the `/api` endpoint | ||
*/ | ||
export const apolloLink = ApolloLink.from([ | ||
// loggerLink, | ||
// if needed, loggerLink goes here | ||
getAuthTokenLink, | ||
retryLink, | ||
errorLink, | ||
apiHttpLink, | ||
]); | ||
|
||
/* | ||
LINK PROCESS (1, 2, 3, 4, 5 => SERVER => 5, 4, 3, 2, 1) | ||
1) loggerLink | ||
Gets called every time no matter what. | ||
2) getAuthTokenLink | ||
Sets Authorization header; value will be null if !token. | ||
3) retryLink | ||
CAN ONLY CATCH NETWORK ERRORS, NOT GraphQL ERRORS! | ||
4) errorLink | ||
Logs errors AND MOST IMPORTANTLY, GraphQL Errors can only be caught here! | ||
errorLink CAN ALSO RETRY REQUESTS! When AuthenticationError is thrown on | ||
the server, that comes back as a GraphQL error that can ONLY be caught here! | ||
So it is HERE that we make the switch to retry and go to /auth/token. | ||
5) authSplitterLink | ||
If operationName is Login/Register, go to restLink (/auth endpoint) | ||
Else go to apiHttpLink (/api endpoint) | ||
*/ |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.