Closed RyanSea closed 1 year ago
Are you using node to run your example ? I got the same error using ts-node and following the suggested solution from the error output works. It basically tells you that you don't have any fetch library available, thus are unable to perform fetch operations.
import fetch from 'cross-fetch';
import {
ApolloClient,
InMemoryCache,
ApolloProvider,
useQuery,
gql,
HttpLink
} from "@apollo/client";
// move URI into the link
const client = new ApolloClient({
cache: new InMemoryCache(),
link: new HttpLink({ uri: 'https://48p1r2roz4.sse.codesandbox.io', fetch })
});
client
.query({
query: gql`
query GetRates {
rates(currency: "USD") {
currency
}
}
`
})
.then(result => console.log(result));
Notice that we need to move the URI inside the link, see more info in the docs
👋 I'm going to close this one out as the suggestion from @Cat-Lord is the way to resolve this problem. Thanks for asking this question.
Intended outcome:
I'm unable to get Apollo to run at all, starting with Getting Started from the docs. (I'm not intending to run Apollo in a browser) First, I had to change
const {ApolloClient} = requirerequire("@apollo/client");
intoconst {ApolloClient} = requirerequire("@apollo/client/core");
, because it gave errors since I wasn't running react (see: Apollo Issue #7005 )Here is the code I'm running, it's from Getting Started in the docs:
Actual outcome:
Getting this error:
How to reproduce the issue:
This is an otherwise empty repository. See versions
Versions
System: OS: macOS 11.2 Binaries: Node: 16.13.1 - ~/.nvm/versions/node/v16.13.1/bin/node Yarn: 1.22.17 - ~/.nvm/versions/node/v16.13.1/bin/yarn npm: 8.1.2 - ~/.nvm/versions/node/v16.13.1/bin/npm Browsers: Chrome: 99.0.4844.83 Safari: 14.0.3 npmPackages: @apollo/client: ^3.5.10 => 3.5.10