我试图使用node.js服务器上的Apollo Client使用以下代码与另一个GraphQL API连接:
import fetch from 'node-fetch'
import { createHttpLink } from 'apollo-link-http'
import ApolloClient from 'apollo-boost'
import { API_URL } from '...'
const client = new ApolloClient({
link: createHttpLink({
uri: API_URL,
fetch: fetch,
}),
})
Run Code Online (Sandbox Code Playgroud)
这会产生以下错误:
module initialization error: Error
fetch is not found globally and no fetcher passed, to fix pass a fetch for
your environment like https://www.npmjs.com/package/node-fetch.
For example:
import fetch from 'node-fetch';
import { createHttpLink } from 'apollo-link-http';
const link = createHttpLink({ uri: '/graphql', fetch: fetch …
Run Code Online (Sandbox Code Playgroud)