Want to get peoples by passing array from the rest api in Graph Studio

@markmegerian
@Jon_Herke
Hi there,
I am passing an array from the rest API and I want the all peoples objects which are passed in an array in GSQL
For example:
This is I am passing from my rest API {“fellow_id”: 2, “peoples_id”: [“Tom”, “Paul”, “Ronny”]}

and the code which I am executing in my GSQL (Graph Studio)
CREATE QUERY consult_peoples(SET(STRING> peoples_id, string fellow_id="") FOR GRAPH doctors syntax v2 {
all_peoples = {people.*};
consult_peoples = select p from all_peoples:p where p.id in peoples_id;
PRINT consult_peoples;
Issue This consult_peoples gives me empty result
}
@Leo_Shestakov please help its urgent
Using parameters in GSQL consult_peoples(SET(STRING> peoples_id, string fellow_id="")

Hey,

So I tried recreating an equivalent version of your query and it seems to be working fine. The part that may be giving you problems is the way you declare your string set argument.

It should be SET<STRING> peoples_id instead of SET(STRING> peoples_id

I understand you may have just changed the code formatting so the forum editor wouldn’t hide the caret symbols, so if that is not the issue there may be a problem with how you are passing arguments through the API. Additionally, try removing the Syntax v2 declaration since you are not actually utilizing any of its features.

I would also recommend using peoples_id.contains(p.id) instead of p.id IN peoples_id (but they should be equivalent in theory).

@Leo_Shestakov thanks for your response
Yaa right I changed the code formatting so the forum editor wouldn’t hide the caret symbols. But i removed syntax v2 and i tried it again give me the empty result in API resonse but its working fine when we are running it from graph studio

I tried these two types from API:
{“fellow_id”: 2, “peoples_id”: [“Tom”, “Paul”, “Ronny”]}
{“fellow_id”: 2, “peoples_id”: (“Tom”, “Paul”, “Ronny”)}
But no one gives required result

z = select s from p:s where context_ids.contains(s.gender);
PRINT z.size(); -> returns 0 in API

@pkr2 Can you verify data is in the graph? In the past, I ran into an empty return. Finally decided to check my data and I’m like “duh I forgot to load the data”

It looks like “fellow_id” is of type STRING in your query, but in the JSON you are supplying an INT. Perhaps that is causing the issue?

For anyone that stumbles across this in the future and wonders how to pass a set parameter to a query via CURL here’s an example. First, schema and query script:
create graph test_graph()
use graph test_graph
create schema_change job test_set_schema for graph test_graph{
add vertex test_set_vertex(PRIMARY_ID id string, test_set_attr set<string>);
}
run schema_change job test_set_schema
create query test_set_query(set<string> param) for graph test_graph{print param;}
install query test_set_query

Next, curl command for post with parameter passed in URL:
$ curl 'http://localhost:9000/query/test_graph/test_set_query?param=a&param=b&param=c'
{"version":{"edition":"enterprise","api":"v2","schema":3},"error":false,"message":"","results":[{"param":["c","b","a"]}]}

Finally, curl command for post with parameter passed as JSON:
$ curl -X POST 'http://localhost:9000/query/test_graph/test_set_query' -d '{"param": ["a", "b", "c"]}'
{"version":{"edition":"enterprise","api":"v2","schema":3},"error":false,"message":"","results":[{"param":["c","b","a"]}]}

1 Like