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
{{ message }}
This repository has been archived by the owner on Apr 14, 2023. It is now read-only.
When starting a new project, Eslint gives the following errors on Apollo imports, which is new for me. Previous projects with same setup, doesn't complain about it.
This is my apolloProvider.tsx:
import React from "react";
import {
ApolloClient,
ApolloProvider,
InMemoryCache,
createHttpLink,
from,
split,
} from "@apollo/client";
import { setContext } from "@apollo/client/link/context";
import { onError } from "@apollo/client/link/error";
import { getMainDefinition } from "@apollo/client/utilities";
import { WebSocketLink } from "@apollo/client/link/ws";
import { getBackendUri, getWebsocketUri } from "../utils/getEnv";
const httpLink = createHttpLink({
uri: `${getBackendUri()}/graphql`,
credentials: "include",
});
const wsLink = new WebSocketLink({
uri: `${getWebsocketUri()}`,
options: {
reconnect: true,
},
});
// The split function takes three parameters:
//
// * A function that's called for each operation to execute
// * The Link to use for an operation if the function returns a "truthy" value
// * The Link to use for an operation if the function returns a "falsy" value
const splitLink = split(
({ query }) => {
const definition = getMainDefinition(query);
return (
definition.kind === "OperationDefinition" &&
definition.operation === "subscription"
);
},
wsLink,
httpLink
);
const authLink = setContext((_, { headers }) => {
// get the authentication token from local storage if it exists
const token = localStorage.getItem("token");
// return the headers to the context so httpLink can read them
return {
headers: {
...headers,
authorization: token ? `Bearer ${token}` : "",
},
};
});
const errorLink = onError(({ graphQLErrors, networkError }) => {
if (graphQLErrors)
graphQLErrors.map(({ message, locations, path }) =>
console.log(
`[GraphQL error]: Message: ${message}, Location: ${JSON.stringify(
locations
)}, Path: ${path}`
)
);
if (networkError) console.log(`[Network error]: ${networkError}`);
});
const client = new ApolloClient({
link: from([authLink, errorLink, splitLink]),
cache: new InMemoryCache(),
});
interface Props {
children: React.ReactNode;
}
const Client = (props: Props) => {
const { children } = props;
return <ApolloProvider client={client}>{children}</ApolloProvider>;
};
export default Client;
This is the error from Eslint:
'@apollo/client/link/ws' should be listed in the project's dependencies. Run 'npm i -S @apollo/client/link/ws' to add iteslintimport/no-extraneous-dependencies
Running the provided command is not working.
The error is for all the following imports:
import { setContext } from "@apollo/client/link/context";
import { onError } from "@apollo/client/link/error";
import { getMainDefinition } from "@apollo/client/utilities";
import { WebSocketLink } from "@apollo/client/link/ws";
Running "@apollo/client": "^3.3.18"
Anyone else had this issue?
The text was updated successfully, but these errors were encountered:
Hi all,
When starting a new project, Eslint gives the following errors on Apollo imports, which is new for me. Previous projects with same setup, doesn't complain about it.
This is my apolloProvider.tsx:
This is the error from Eslint:
'@apollo/client/link/ws' should be listed in the project's dependencies. Run 'npm i -S @apollo/client/link/ws' to add iteslintimport/no-extraneous-dependencies
Running the provided command is not working.
The error is for all the following imports:
Running "@apollo/client": "^3.3.18"
Anyone else had this issue?
The text was updated successfully, but these errors were encountered: