-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
CRDCDH-95 Add apollo client and integrated with mock api server
- Loading branch information
Showing
12 changed files
with
572 additions
and
207 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* eslint-disable */ | ||
import { | ||
ApolloClient, InMemoryCache, ApolloLink, HttpLink, DefaultOptions | ||
} from '@apollo/client'; | ||
import env from './env'; | ||
|
||
const defaultOptions:DefaultOptions = { | ||
query: { | ||
fetchPolicy: 'no-cache', | ||
}, | ||
}; | ||
|
||
const BACKEND = env.REACT_APP_BACKEND_API; | ||
const MOCK = 'https://7a242248-52f7-476a-a60f-d64a2db3dd5b.mock.pstmn.io/graphql'; | ||
const AUTH_SERVICE = `${env.REACT_APP_AUTH_SERVICE_API}graphql`; | ||
const USER_SERVICE = `${env.REACT_APP_USER_SERVICE_API}graphql`; | ||
|
||
const backendService = new HttpLink({ | ||
uri: BACKEND, | ||
}); | ||
|
||
const authService = new HttpLink({ | ||
uri: AUTH_SERVICE, | ||
}); | ||
|
||
const userService = new HttpLink({ | ||
uri: USER_SERVICE, | ||
}); | ||
|
||
|
||
const mockService = new HttpLink({ | ||
uri: MOCK, | ||
headers: { | ||
'x-mock-match-request-body': 'true', | ||
}, | ||
}); | ||
|
||
const client = new ApolloClient({ | ||
cache: new InMemoryCache(), | ||
defaultOptions, | ||
link: ApolloLink.split( | ||
(operation) => operation.getContext().clientName === 'mockService', | ||
mockService, | ||
ApolloLink.split( | ||
(operation) => operation.getContext().clientName === 'authService', | ||
// the string "authService" can be anything you want, | ||
authService, // <= apollo will send to this if clientName is "authService" | ||
ApolloLink.split( // This is 2nd level of ApolloLink. | ||
(operation) => operation.getContext().clientName === 'userService', | ||
// the string "userService" can be anything you want, | ||
userService, // <= apollo will send to this if clientName is "userService" | ||
backendService, // <= otherwise will send to this | ||
), // <= otherwise will send to this | ||
), | ||
), | ||
}); | ||
|
||
|
||
export default client; |
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
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
Oops, something went wrong.