Created
September 27, 2024 09:27
-
-
Save umutyerebakmaz/ef3a6e2db80ea3b7711e6fb1204e05b4 to your computer and use it in GitHub Desktop.
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
import { HttpLink } from 'apollo-angular/http'; | |
import { ApolloLink, InMemoryCache } from '@apollo/client/core'; | |
import { setContext } from '@apollo/client/link/context'; | |
import { environment } from '@environments/environment'; | |
import { extractFiles } from 'extract-files'; | |
export function createApolloClient(httpLink: HttpLink) { | |
const uri = `${environment.backendURL}/graphql`; | |
const auth = setContext((operation, context) => { | |
const accessToken = localStorage.getItem('accessToken'); | |
return { | |
...context['headers'], | |
headers: { | |
Authorization: accessToken ? `Bearer ${accessToken}` : '', | |
}, | |
}; | |
}); | |
const link = ApolloLink.from([ | |
auth, | |
httpLink.create({ | |
uri, | |
useMultipart: true, | |
extractFiles, | |
}), | |
]); | |
const cache = new InMemoryCache(); | |
const defaultOptions = { | |
watchQuery: { | |
fetchPolicy: 'cache-first', | |
}, | |
query: { | |
fetchPolicy: 'cache-first', | |
}, | |
}; | |
return { | |
link, | |
cache, | |
defaultOptions, | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment