Skip to main content
Announcements
Live today at 11 AM ET. Get your questions about Qlik Connect answered, or just listen in. SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
steeramp
Partner - Creator II
Partner - Creator II

How to make data connection REST GET GraphQL ?

Hi to every one,

I need to create one Data Connection for to read some fields in GraphQL

example :

 query{
bookings {
id
uuid
}
}

the URL it's something like this :

"https://gm-cms-staging.xyyyy.com/graphql?token=a5OMOWlzCB9zM_os0oS8"

Someone has used REST GET JSON with GraphQL ?

Thanks so much for your help !!

1 Solution

Accepted Solutions
6 Replies
jptneumann
Partner Ambassador
Partner Ambassador

salonibhatia
Contributor III
Contributor III

Hi @steeramp ,

Hope the connection has worked for you. Am trying to make the query dynamic. Have been able to connect with the Rest API and query a table based on the response query in the data connection but it doesn't work when i try and use with connection to query a different table. Any guidance will be helpful.

 

Thanks!

jptneumann
Partner Ambassador
Partner Ambassador

Hi  @salonibhatia ,
Yes, it is possible. Just make your SQL Select using WITH CONNECTION . For example:

let vRequestBody = '{ "query": "{ organizations { id name created_at role} }"}';
let vRequestBody = replace(vRequestBody,'"', chr(34)&chr(34));

LIB CONNECT TO 'mysourceAPI';

RestConnectorMasterTable:
SQL SELECT
"__KEY_data",
(SELECT
"id",
"name",
"created_at",
"role",
"__FK_organizations"
FROM "organizations" FK "__FK_organizations")
FROM JSON (wrap off) "data" PK "__KEY_data"
WITH CONNECTION(Url "https://api.mysource.com/graphql", BODY "$(vRequestBody)");


If you need connect to a sequence of tables, you can loop a list of tables and make a connection for each table.

Regards,

Jean Paul

salonibhatia
Contributor III
Contributor III

Thanks @jptneumann 

The columns in each table are different. Will the query have to be written every time to get the columns of that particular table? Am sorry for a lot of questions but little confused since if you change the query from organizations to a different table say departments and departments table has different columns, then how do you handle that part?

 

Thanks in advance 🙂 

salonibhatia
Contributor III
Contributor III

Hi @jptneumann , found a solution to add columns using a variable in select query as below

Let vColumns = 'a","b","c';

 My approach would be to fetch columns somehow automatically in the variable based on table name(still have to work on it); have researched and * doesn't work.

Please do share if there is any better approach.

 

Thanks,

Saloni

jptneumann
Partner Ambassador
Partner Ambassador

Hi @salonibhatia ,

it is a good option to use variables.

See in the example that the request uses the vRequestBody variable to build the query and it can be changed whenever you need to change the query.

To select the fields according to the table name, I suggest using the combination of Pick and Match functions.

Ex:

Pick(Match(vTable, 'Table1','Table2','Table3'),'Field1, Field2', 'Field3,Field4','Field5,Field6')

I hope I helped you,

Regards,

Jean Paul