Closed batjko closed 8 years ago
Are you using IE by any chance? If yes, this is the issue discussed in #126, and basically you will need to bring some fetch polyfill to the client, for instance with https://www.npmjs.com/package/isomorphic-fetch.
This is in Node, not from a browser. I have a separate GraphQL service running, to which I am trying to connect from my node app. (I've updated the issue description now to point that out) Node 5.10.1, 64bit.
I've just seen the related issue as well, but I thought the isomorphic-fetch pakcage is essentially the problem?
So apparently Node v5 is also missing the fetch
method:
$ nvm use node 5
$ echo "console.log(typeof fetch)" | node
undefined
I think that something the Apollo crew should fix. Meanwhile you can load a fetch
polyfill from NPM (either isomorphic-fetch or maybe https://www.npmjs.com/package/node-fetch) and define it as a global variable (eg. fetch = require('node-fetch');
) so that the Apollo-client code could use it.
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?
Edited (Forget what I wrote in this comment earlier, I just hadn't changed my query variables to retrieve the right data.)
fetch = require('node-fetch')
works, though a bit of a hack for now.
I think we made an intentional decision to not include global polyfills in here, so changing this issue to be about documenting the polyfills required.
I had the same issue and i added es6-promise
and isomorphic-fetch
and now i am getting the error
self not defined
I 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"; }
Hi guys,
So I am trying to replace my
graphql-js
client in a Node app, with theapollo-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:
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.