Why am i getting this error: TypeError: undefined is not a function #3292
-
I'm using import React from "react";
import {
Client,
Provider,
cacheExchange,
fetchExchange,
subscriptionExchange,
} from "urql";
import { KEYS, serverDomain } from "../constants";
import { del, retrieve } from "../utils";
import { createClient as createSSEClient } from "graphql-sse";
import { authExchange } from "@urql/exchange-auth";
interface Props {
children: React.ReactNode;
}
const sseClient = createSSEClient({
url: `http://${serverDomain}/graphql`,
});
const client = new Client({
url: `http://${serverDomain}/graphql`,
requestPolicy: "network-only",
exchanges: [
cacheExchange,
authExchange(async (utils) => {
const jwt = await retrieve(KEYS.TOKEN_KEY);
return {
addAuthToOperation(operation) {
if (jwt) {
return utils.appendHeaders(operation, {
Authorization: `Bearer ${jwt}`,
});
}
return operation;
},
willAuthError(_operation) {
return !jwt;
},
didAuthError(error, _operation) {
return error.graphQLErrors.some(
(e) => e.extensions?.code === "FORBIDDEN"
);
},
async refreshAuth() {
await del(KEYS.TOKEN_KEY);
},
};
}),
fetchExchange,
subscriptionExchange({
forwardSubscription(operation) {
return {
subscribe: (sink) => {
const dispose = sseClient.subscribe(operation as any, sink);
return {
unsubscribe: dispose,
};
},
};
},
}),
],
});
const UrqlProvider: React.FunctionComponent<Props> = ({ children }) => {
return <Provider value={client}>{children}</Provider>;
};
export default UrqlProvider; If I try to make a query or mutation to the server i get the error saying: TypeError: undefined is not a function. But if i comment the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I managed to solve my issue by dong the following.
yarn add core-js Then add the following import at the top in the root component of my app: import 'core-js/full/symbol/async-iterator'; |
Beta Was this translation helpful? Give feedback.
I managed to solve my issue by dong the following.
core-js
Then add the following import at the top in the root component of my app: