Apollo Client change uri (Http Link)

Viewed 93

I am using Apollo Client and the code is following:

const link = new HttpLink({
   uri: "https://localhost:8888/graphql/" + 
   JSON.parse(localStorage.getItem("preferences")).**id** + "/query",
});


const client = new ApolloClient({
   link: authLink.concat(link),
   cache: new InMemoryCache(),
  fetchOptions: {
    mode: "no-cors",
  },
  defaultOptions: defaultOptions,
});

......

const AppMain = () => {
return (
    <Provider store={store}>
        <OidcProvider userManager={userManager} store={store}>
            <div className="App">
                <BrowserRouter>
                    <ApolloProvider client={client}>
                        <App />
                    </ApolloProvider>
                </BrowserRouter>
            </div>
        </OidcProvider>
    </Provider>
);
};

export default AppMain;

So when id changed from localStorage and the page is not refreshed the next gql request happen with previous id instead of new one.

So how can I update uri inside App child components?

0 Answers
Related