How to invoke GraphQL API in script to query tables

IronPotato
Mega Sage

Hi All, 

 

I’m trying to implement GraphQL into project to basically replace GlideRecord queries with GraphQL gueries to retrieve table data. 

I have GraphQL API, resolver and mapping and I’m able to test it via GraphQL Explorer but how to make use of it in script include? How can I actually invoke it?

 

Any help would be appreciated.

 

Thanks

1 REPLY 1

Quang Nguyen1
Tera Contributor

GraphQL is normally being called from client side. However, if you want to call it from a script include, you "potentially" could setup a Rest Message and post your GQL to your instance "/api/now/graphql" endpoint. Please note that I have not tested this but it's an option.

Hope that help.

try { 
 var r = new sn_ws.RESTMessageV2('YOUR_REST_MESSAGE', 'REST_MESSAGE_METHOD');
 var response = r.execute();
 var responseBody = response.getBody();
 var httpStatus = response.getStatusCode();
}
catch(ex) {
 var message = ex.message;
}