Tigroid JS Wrapper

Has anyone tried using the Tigroid.js package for connecting to TigerGraph from a JS function? I’m having some trouble, and I’d like to know if there are any projects done using it or if anyone has experience with it.

Hi Akash,

I am the author of the Tigroid.js solution. Could you please describe what would you like to achieve so that I can help you properly?
This solution is massively work-in-progress, but I have used in a number of demos successfully. I am not a 100% JS guru, so any suggestions and corrections are welcome.

Szilard :tiger2:

Hi,

Thanks for responding. I am running into a CORS issue. Whenever I try to instantiate the Tigroid class and call a query I get “Origin null is not allowed by Access-Control-Allow-Origin”. I am not too familiar with JS or server-client communications, and I’ve tried some recommended solutions online with no luck.

Any help would be greatly appreciated.

Thank you,
Akash

Hi,

I too have come across CORS issues a lot. I can’t say I have a full solution yet (we are looking into it). One thing that worked for me was using a proxy to send all request through the same URL/domain. This included setting Access-Control-Allow-Origin and Access-Control-Allow-Methods headers.

I have included the Node.js core below. This is not perfect, but worked as/when needed.

I think the real solution would be something like a proper Node.js app and AJAX requests from the web page to it. This is planned in near future; but I am still also would like to see how much can be done with client-side scripting only.

All settings can be configured via environment vars.
@Bruno is the source of the proxy code, and he has more Node.js skills than me, maybe he can help too.

const proxy   = require('express-http-proxy');
const app     = require('express')();

const PORT    = process.env.PORT || 8080;

const TGHOST  = process.env.TGHOST  || 'localhost';
const APIPORT = process.env.APIPORT || 9000;
const GSPORT  = process.env.GSPORT  || 14240;

app.use('/gsqlserver', proxy(TGHOST + ':' + GSPORT, {
    proxyReqPathResolver: function (req) {
        let newReqUrl = '/gsqlserver' + req.url;
        console.log(req.url + " → " + newReqUrl);
        return newReqUrl;
    },

    proxyReqOptDecorator: function(proxyReqOpts, srcReq) {
        proxyReqOpts.headers['authorization'] = 'Basic dGlnZXJncmFwaDp0aWdlcmdyYXBo';
        return proxyReqOpts;
    },

    userResHeaderDecorator: function(headers, userReq, userRes, proxyReq, proxyRes) {
        headers['Access-Control-Allow-Origin'] = '*';
        headers['Access-Control-Allow-Methods'] = 'GET, POST, PATCH, PUT, DELETE, OPTIONS';
        headers['Content-Type'] = 'application/json; charset=utf-8';
        //console.log(headers);
        return headers;
    }
}));
app.use('/', proxy(TGHOST + ':' + APIPORT, {
    proxyReqPathResolver: function (req) {
        console.log(req.url);
        return req.url;
    },

    userResHeaderDecorator: function(headers, userReq, userRes, proxyReq, proxyRes) {
        headers['Access-Control-Allow-Origin'] = '*';
        headers['Access-Control-Allow-Methods'] = 'GET, POST, PATCH, PUT, DELETE, OPTIONS';
        //console.log(headers);
        return headers;
    }
}));

app.listen(PORT, () => {
    console.log(`Proxy is listening on port ${PORT}...`);
});

and

https://expressjs.com/

Ok I see. I was hoping that there was an easier way to do this, but I guess this is the only solution for now.
I’ll try and implement the proxy code you attached and see if I can get something working.

Thank you,
Akash

I/We definitely want to find the simples possible solution that would be simply linking the .js file from somewhere and then set up the connection.
As I mentioned, this is work-in-progress, as soon as we have it working, we will release a new version.

Hey I just though I’d give an update on the Tigroid wrapper. I used a remote proxy hosted on heroku (https://cors-anywhere.herokuapp.com) to manage the CORS issues.

I actually used the Tigroid wrapper to integrate TigerGraph with Swift on a demo iOS app. I created a html/js page and displayed it on the app. It was mainly just to see if this was possible, but I think the applications are pretty limited.

Here’s demo of the functionality:
https://drive.google.com/file/d/1u89_YGiHatK5XomGeOzwfYeVrjNHCFLA/view?usp=sharing

Thanks for all of your help!
Akash