const httpLink = createHttpLink({
uri: "https://graphql-demo.dev.aicall.ru/graphql",
});
const authMiddleware = new ApolloLink((operation, forward) => {
operation.setContext(({ headers = {} }) => ({
headers: {
...headers,
authorization: localStorage.getItem("token") || null,
},
}));
return forward(operation);
});
const removeTypenameLink = removeTypenameFromVariables();
const link = concat(authMiddleware, httpLink);
export async function getDashboardData() {
const token = localStorage.getItem("token");
if (!token) return new Error("Отсутствует токен");
const client = new ApolloClient({
cache: new InMemoryCache({
typePolicies: {
Query: {
fields: {
"*": {
read(existing) {
return existing;
},
},
},
},
},
}),
link: ApolloLink.from([removeTypenameLink, link]),
headers: {
Authorization: `Bearer ${token}`,
},
});
I tried many times, even connected ChatGPT, but it’s useless, __typename just don’t want to be deleted, pls help.