Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi everyone,
I am trying to create a rest API connection to fetch data from Graph QL. At the moment, connection is working. However, i need to make it dynamic that is to have the capability to query any table using the connection. While creating the Rest API connection, response body is required and have passed a JSON body querying a table. After that, am trying query a different table using With statement but that is not working. Any suggestions on how to pass blank query in rest API connection so later on i can query any table by changing it in script.
Just to summarize need help with below pointers:
1. How to pass blank query in rest API connection so later on i can query any table by changing it in script?
2. how to add filters to the JSON query? In apollo, it is passed in the variable section and there are multiple filters.
Thanks in advance 🙂
@salonibhatia - This link is the help content needed to achieve this. I include a working example of this below, use Graph QL to query two different sources, with one connection defined.
LIB CONNECT TO 'SharedConnections:REST_graphql_countries';
RestConnectorMasterTable:
SQL SELECT
"__KEY_data",
(SELECT
"name",
"__FK_continents"
FROM "continents" FK "__FK_continents")
FROM JSON (wrap off) "data" PK "__KEY_data";
[continents]:
LOAD [name],
[__FK_continents] AS [__KEY_data]
RESIDENT RestConnectorMasterTable
WHERE NOT IsNull([__FK_continents]);
[continents_data]:
LOAD [__KEY_data]
RESIDENT RestConnectorMasterTable
WHERE NOT IsNull([__KEY_data]);
DROP TABLE RestConnectorMasterTable;
disconnect;
//
LIB CONNECT TO 'Shared Data Connections:REST_graphql_countries';
RestConnectorMasterTable:
SQL SELECT
"__KEY_data",
(SELECT
"launch_success",
"launch_date_local",
"__KEY_launchesPast",
"__FK_launchesPast",
(SELECT
"rocket_name",
"__FK_rocket"
FROM "rocket" FK "__FK_rocket")
FROM "launchesPast" PK "__KEY_launchesPast" FK "__FK_launchesPast")
FROM JSON (wrap off) "data" PK "__KEY_data"
// URL "new url"
// QUERY "parameter name" "parameter value"
// HTTPHEADER "header name" "header value"
// BODY "request body text"
WITH CONNECTION (
URL "https://api.spacex.land/graphql",
HTTPHEADER "Content-Type" "application/json",
HTTPHEADER "Accept" "application/json",
// Note how each double quote inside the query needs to be "double-double-quoted" so Engine escapes them. The DLE syntax highlight will look wrong.
BODY "{""query"":""{\n launchesPast(limit: 10) {\n rocket {\n rocket_name\n }\n launch_success\n launch_date_local\n }\n}""}"
);
[rocket]:
LOAD [rocket_name],
[__FK_rocket] AS [__KEY_launchesPast]
RESIDENT RestConnectorMasterTable
WHERE NOT IsNull([__FK_rocket]);
[launchesPast]:
LOAD [launch_success],
[launch_date_local],
[__KEY_launchesPast],
[__FK_launchesPast] AS [__KEY_data]
RESIDENT RestConnectorMasterTable
WHERE NOT IsNull([__FK_launchesPast]);
[launchesPast_data]:
LOAD [__KEY_data]
RESIDENT RestConnectorMasterTable
WHERE NOT IsNull([__KEY_data]);
DROP TABLE RestConnectorMasterTable;
disconnect;
This REST connection used above was created using a POST method, and is redefined by using the WITH CONNECTION statement to a completely different Graph QL service.
@salonibhatia - This link is the help content needed to achieve this. I include a working example of this below, use Graph QL to query two different sources, with one connection defined.
LIB CONNECT TO 'SharedConnections:REST_graphql_countries';
RestConnectorMasterTable:
SQL SELECT
"__KEY_data",
(SELECT
"name",
"__FK_continents"
FROM "continents" FK "__FK_continents")
FROM JSON (wrap off) "data" PK "__KEY_data";
[continents]:
LOAD [name],
[__FK_continents] AS [__KEY_data]
RESIDENT RestConnectorMasterTable
WHERE NOT IsNull([__FK_continents]);
[continents_data]:
LOAD [__KEY_data]
RESIDENT RestConnectorMasterTable
WHERE NOT IsNull([__KEY_data]);
DROP TABLE RestConnectorMasterTable;
disconnect;
//
LIB CONNECT TO 'Shared Data Connections:REST_graphql_countries';
RestConnectorMasterTable:
SQL SELECT
"__KEY_data",
(SELECT
"launch_success",
"launch_date_local",
"__KEY_launchesPast",
"__FK_launchesPast",
(SELECT
"rocket_name",
"__FK_rocket"
FROM "rocket" FK "__FK_rocket")
FROM "launchesPast" PK "__KEY_launchesPast" FK "__FK_launchesPast")
FROM JSON (wrap off) "data" PK "__KEY_data"
// URL "new url"
// QUERY "parameter name" "parameter value"
// HTTPHEADER "header name" "header value"
// BODY "request body text"
WITH CONNECTION (
URL "https://api.spacex.land/graphql",
HTTPHEADER "Content-Type" "application/json",
HTTPHEADER "Accept" "application/json",
// Note how each double quote inside the query needs to be "double-double-quoted" so Engine escapes them. The DLE syntax highlight will look wrong.
BODY "{""query"":""{\n launchesPast(limit: 10) {\n rocket {\n rocket_name\n }\n launch_success\n launch_date_local\n }\n}""}"
);
[rocket]:
LOAD [rocket_name],
[__FK_rocket] AS [__KEY_launchesPast]
RESIDENT RestConnectorMasterTable
WHERE NOT IsNull([__FK_rocket]);
[launchesPast]:
LOAD [launch_success],
[launch_date_local],
[__KEY_launchesPast],
[__FK_launchesPast] AS [__KEY_data]
RESIDENT RestConnectorMasterTable
WHERE NOT IsNull([__FK_launchesPast]);
[launchesPast_data]:
LOAD [__KEY_data]
RESIDENT RestConnectorMasterTable
WHERE NOT IsNull([__KEY_data]);
DROP TABLE RestConnectorMasterTable;
disconnect;
This REST connection used above was created using a POST method, and is redefined by using the WITH CONNECTION statement to a completely different Graph QL service.
Original connection information/body showing filter in use.