Extend computed fields with additional parameters

Open
#295 5 comments 2 reactions 1 assignee View on GitHub

@olirice is already working on this.

Since Dec 27, 2022.

Assessment

This issue has not been assessed yet.

Description

enhancement

Summary

To allow

create or replace function app._last_events(app.project, count int) returns ...

to be natively used like

query GetProjects {
  projectCollection {
    edges { node { id code name lastEvents(count: 1) } }
  }
}

Rationale

To allow for a richer computed fields resolution logic.

Design

We already analyze computed field functions signatures to insert them into the schema.
I believe we could as well detect function argument name and type and auto-add schema input fields for additional arguments.

Drawbacks

Don't see any.

Alternatives

Certainly we can pass additional info down to computed field resolver via global variables by doing

set_config('graphql.vars', $1->>'variables', true)

in app.graphql() and using

coalesce(current_setting('graphql.vars', true)::jsonb->>'count', '1')::int

in the computed field function.

The above is just a lot of hackish plus it pushes to pass data beside the schema and bypasses input validation.

Dominant language
Rust
Stars
3.4k
Forks
141
Avg merge
19m
Merged PRs (30d)
2

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from supabase/pg_graphql

All issues in supabase/pg_graphql

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.