Document that `fetch` polyfill is required when using from Node
See original GitHub issueHi guys,
So I am trying to replace my graphql-js
client in a Node app, with the apollo-client
instead.
To start off, I’ve basically copied the code snippet from the docs and just replaced the query with my own (which I know works).
But now the query fails, jumping to the catch clause instead.
This is the example code, with a simplified version of my query:
const queryVars = {
id: 2,
bunit: 'TestUnit'
};
client.query({
query: `query getStuff(
$id: Int,
$bunit: String
){
forecasts (
id: $id,
bunit: $bunit
) {
id,
bunit
}
}
`,
variables: queryVars,
forceFetch: false
}).then((graphQLResult) => {
const { errors, data } = graphQLResult;
if (data) {
console.log('got data', data);
}
if (errors) {
console.log('got some GraphQL execution errors', errors);
}
}).catch((error) => {
console.log('there was an error sending the query', error);
});
I can only assume this fetch
call is internal to apollo, since it’s not part of my code.
Do I need to have any other dependency installed by chance?
This is on Windows, btw.
Issue Analytics
- State:
- Created 7 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Polyfilling the Fetch API for Old Browsers and Node.js
First some definitions. A polyfill will try to emulate certain APIs, so can use them as if they were already implemented. A transpiler...
Read more >node-fetch-polyfill - npm
A light-weight module that brings window.fetch to node.js. Latest version: 2.0.6, last published: 6 years ago. Start using ...
Read more >Using the fetch API inside Node.js - Christoph Zauner's Blog
Webpack config · In the client bundle we include a fetch polyfill for older browsers ( whatwg-fetch ). · We tell the webpack-node-externals...
Read more >How to use the GitHub Fetch API polyfill - Stack Overflow
First, install using npm install --save whatwg-fetch. then use: require('whatwg-fetch'). You can alternatively use import syntax import 'whatwg-fetch'.
Read more >fetch-polyfill | Yarn - Package Manager
This module is out of maintanance, use fetch-ie8 instead. The global fetch function is an easier way to make web requests and handle...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Reading https://github.com/apollostack/apollo-client/pull/126#issue-149328412 again, it seems like the one-line
import 'isomorphic-fetch'
should be enough, did you try it?I had the same issue and i added
es6-promise
andisomorphic-fetch
and now i am getting the errorI created the following fetch.js file
` require(‘es6-promise’).polyfill(); var fetch=require(‘isomorphic-fetch’).fetch;
const { createApolloFetch } = require(‘apollo-fetch’); const fetchQL = createApolloFetch({ uri: ‘http://localhost:4000/graphql’, });
fetchQL({ query: ‘{testFunction}’, }).then(res => { console.log(res.data.testFunction); }); `
with schema as
type myQuery { testFunction: String! }
and resolver as
myQuery:{ testFunction(){ return "returned from custom test function"; }