I’m trying to get the npm module graphql-request to work with Fuse. I have an empty app where I do the following:
Run npm init
to create a package.json
Run npm install graphql-request --save
to install the package
Run nfuse
to make it available to the Fuse environment
Then, in a JS module inside my app I’m trying to use it with the following code:
var request = ("graphql-request"); // also tried ("graphql-request").request
var endpoint = "https://api.graph.cool/simple/v1/cj5s6t2ts2oo70122p1ht5ye5";
var query = "{ allMessages { text } }";
request(endpoint, query).then(function(data) {
console.log(data);
});
But I’ll only get an error saying: JS stack trace: TypeError: request is not a function
Any ideas how I can make this work?
Hi! It looks to me like you’re missing a require
in the first line
Also, looking at the graphql-request library, it seems like you had the right idea in your comment about require("graphql-request").request
Ah - facepalm ! Not sure if this was the actual issue though or just made it into this post as a typo… I had spent quite some time on the problem and did try a few different approaches… I’ll check if I can get it to work now, thanks for the response anyways!
Hello Nikolas,
Did you get around to making this work? I’m in the exact same situation and no matter how I try to add it, I end up with the following error:
Error message: Uncaught require(): module not found: graphql-request
Thanks
bai
December 26, 2017, 10:42am
5
you can connect through it https://github.com/f/graphql.js/ (does not require node js) if you want to subscribe then look at this example https://github.com/f/graphql.js-demo and it all works through graphcool https://www.graph.cool/ sorry my eng =)
---------------------------------------------------------------------------------------------------