0

Hasura API explorer behaving a bit different than Raw SQL runner's results. I have this custom function.

CREATE 
OR REPLACE FUNCTION public.session_groupings( group_bys TEXT[] DEFAULT '{}', "sessionWhere" json default null ) RETURNS SETOF session_groupings_type LANGUAGE sql STABLE AS $$ 
SELECT

When I run

select session_groupings('{country}', '{"project_id": {"_eq": "951f4001-36fc-4bb7-9d87-e37bd4c56502"},"created_at": {"_gte": "05-10-2021" ,"_lte": "06-10-2021" }}')

This gives me the right results. But when I run it with API explorer the results are wrong I am calling it like

query MyQuery($sessionWhere: json, $group_bys: _text) {
  session_groupings(args: {sessionWhere: $sessionWhere, group_bys: $group_bys}) {
    country_name {
      name
    }
    count
  }
}

then the variables are like so

{
  "group_bys": "{country}",
  "sessionWhere": {
    "project_id": {"_eq": "951f4001-36fc-4bb7-9d87-e37bd4c56502"},
    "created_at": {"_gte": "05-10-2021" ,"_lte": "06-10-2021" }
  }
}

Am I calling it the wrong way?

Subhendu Kundu
  • 3,618
  • 6
  • 26
  • 57
  • Hm. I would check Permissions->Row Select Permissions defined for `sessions_groupings`. Do you have them defined? – Alex Yu Jul 28 '21 at 04:30
  • I have it set to admin to all. And fetching with admin secret. Plus it is going me back a set of data. But it is not filtering it out the right set. – Subhendu Kundu Jul 28 '21 at 04:54
  • Strange. I created a function that just returns passed json parameter to check if the parameter is not changed when passed by hasura. It seems it's the same. I would click "Analyze" in hasura console, copy-paste SQL and execute it. Does it works the same way? Is there something suspicious in generated SQL code? – Alex Yu Jul 28 '21 at 05:32
  • That is a bit of hope then. Not just me then? Let me click "Analyze". If you want to have access to my hasura, lets talk in discord? – Subhendu Kundu Jul 28 '21 at 05:54
  • This is for https://github.com/subhendukundu/cool-bio-analytics – Subhendu Kundu Jul 28 '21 at 05:55
  • I ran the "Analyze" and the sql not returning the expected result as it should in the `select session_groupings` – Subhendu Kundu Jul 28 '21 at 06:06
  • You must have `SELECT * FROM "public"."session_groupins"( .. your params here ..)` in generated sql. Hm. Another question: `country_name {name}` is a json field returned by function `session_groupings` or that an object relation ? – Alex Yu Jul 28 '21 at 06:16
  • About looking on your hasura: maybe later - I have my work to do today ;) – Alex Yu Jul 28 '21 at 06:18

0 Answers0