You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You can set the header when creating your ApolloClient. You just need to concat the link attribute with a provided context function. Here an example:
...
import { ApolloClient } from 'apollo-client'
import { createHttpLink } from 'apollo-link-http'
import { setContext } from 'apollo-link-context'
//like you would normally do
const httpLink = new createHttpLink({
uri:yourEndpoint
fetch,
})
//-this function will get called every time
//your client tries to communicate with your graphql endpoint
//-you can also import your svelte stores as shown in this example
const authLink = setContext((_, { headers }) => {
return {
headers: {
...headers,
authorization: get(account) ? `Bearer ${get(account).token}` : '',
},
}
})
//now use the provided concat method from your context variable
const client = new ApolloClient({
link: authLink.concat(httpLink)
})
How to add headers for queries or mutations?
It's useful in auth or something else.
The text was updated successfully, but these errors were encountered: