supabase / pg_graphql

GraphQL support for PostgreSQL
https://supabase.github.io/pg_graphql
Apache License 2.0
2.88k stars 101 forks source link

Cannot query with 100+ fields #551

Closed wesharper closed 4 days ago

wesharper commented 1 week ago

Describe the bug We have a relatively complex query for a very wide sql table from which we need almost all of the fields for our client view. To manage this, we have a query split up into 9 separate fragments, each of which specifies between 2 and 50 fields. However, when I attempt to run the query, pg_graphql spits back the following error message: cannot pass more than 100 arguments to a function.

It appears to be similar to issue #353, but I've verified that my pg_graphql version includes the patch for the referenced issue. Is there indeed a 100 field limit on all queries even with the patch?

To Reproduce Steps to reproduce the behavior:

  1. Create table bar, which stores 140 columns.
  2. Create table foo, which stores its own primary key and a reference to a primary key from bar.
  3. Create sql function
    create or replace function get_foo_by_id(foo_id bigint) returns foo language sql stable security invoker as $$
    select *
    from foo
    where id = foo_id;
    $$;
  4. Add dummy data
  5. query
    query {
    getFooById(fooId: 1) {
    bar {
      # 140 fields
    }
    }
    }

Expected behavior The query should execute successfully.

Versions:

Additional context Without deeper knowledge of the transpiler, I attempted to suss out issues that might be related to my own specific use-case. Here are some of the things I tried:

  1. The query relies on a sql function to resolve a singular record i.e. getRecordById, as explained in the repro steps, rather than requesting from a collection resolver. However, when I tried the same query using the collection resolver, I encountered the same issue.
  2. The query uses fragments. However, when I flattened the query to one large mega-query without fragments (about 160 fields total), I still get the same error.
olirice commented 6 days ago

Reproducible Example issue_551_too_many_fields.txt

select jsonb_pretty(
        graphql.resolve($$
            {
              barCollection {
                edges {
                  node {
                    id
                    field1
                    field2
-- works
    select jsonb_pretty(
        graphql.resolve($$
            {
              getFooById(fooId: 1) {
                bar {
                    id
                    field1
                    field2
                    ...
 -- "message": "cannot pass more than 100 arguments to a function"
    select jsonb_pretty(
        graphql.resolve($$
            {
              fooCollection {
                edges {
                  node {
                    bar {
                      id
                      field1
                      field2
-- "message": "cannot pass more than 100 arguments to a function"