Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend computed fields with additional parameters #295

Open
dvv opened this issue Dec 27, 2022 · 3 comments
Open

Extend computed fields with additional parameters #295

dvv opened this issue Dec 27, 2022 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@dvv
Copy link

dvv commented Dec 27, 2022

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.

@olirice olirice changed the title How to pass arguments to computed field functions? Extend computed fields with additional parameters Dec 27, 2022
@olirice
Copy link
Contributor

olirice commented Dec 27, 2022

it isn't currently possible to have additional parameters using the computed column feature. This feature is related to #222 but lets track it separately here as it'll probably be implemented in a separate PR

@olirice olirice self-assigned this Dec 27, 2022
@olirice olirice added the enhancement New feature or request label Dec 27, 2022
@dvv
Copy link
Author

dvv commented Dec 1, 2023

@olirice I managed to generate correct (hopefully) schema fields for the subj here https://github.com/dvv/pg_graphql/blob/master/src/graphql.rs#L2028-L2060.

create or replace function app._roles(app.user, i int = 123, s text = '456') returns text[] stable return array[s]::text[];
roles(i: Int = 123, s: String = "456"): [String]

Then I issue

query profile {
  theUser {
    id
    username
    roles(i: 222, s: "111")
  }
}

but the app._roles() is given only the first argument.

Please point out where to look for passing other arguments?

@olirice
Copy link
Contributor

olirice commented Dec 7, 2023

Please hold off on this feature. We need to make some decisions internally about how to differentiate between functions which extend base types and functions that are on the Query object and that'll have a significant impact on implementation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants