ITADN

Inconsistent handling of optional filter variables for `SETOF SQL` functions gives "Encountered Absent value" error

#617OpenObeyed 创建于 2025-12-12
triage-required
O
Obeyedcommented
This is a cool project, appreciate the work gone into it. I ran into a small behavior that seems inconsistent, and I wanted to share a reproducible example to clarify what I observed. **Describe the bug** SQL functions that return `SETOF <table>` are exposed as GraphQL collections, making it possible to use the `filter` argument and more. However, the handling of optional filter variables is inconsistent compared to normal table collections: - For normal table collections, omitted filter variables are silently ignored (filter clause removed). - For function collections, if a filter variable is not provided (omitted from the GraphQL variables JSON), pg_graphql sometimes throws: ``` Encountered `Absent` value while transforming between GraphQL intermediate object notation and JSON ``` **To Reproduce** Create dummy table and function: ``` create table dummy_table ( id serial primary key, category text ); create or replace function dummy_function () returns setof dummy_table as $$ select t.* from dummy_table t $$ stable language sql; insert into dummy_table (category) values ('CAT A'), ('CAT B'), ('CAT C'); ``` **Query the table** - Try querying the new table collection with **`variables: {}`**. It works fine. ``` { dummy_tableCollection(filter: {category: {eq: $filter_category}}) { edges { node { id category } } } } ``` **Query the function** - Try querying the new function now with **`variables: {}`**. It produces the "Absent" error. - Try querying with **`variables: { "filter_category": "CAT A" }`**, it works as expected doing the expected filtering. ``` { dummy_function(filter: {category: {eq: $filter_category}}) { edges { node { id category } } } } ``` **Expected behavior** Optional filter variables in function collections should behave like table collections: - If the variable is omitted, the filter should be ignored rather than producing an Absent error. **Versions:** - PostgreSQL: 15 - pg_graphql version: 1.5.11
1 条评论