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

Conditionally exclude fields from Query #470

Open
dvv opened this issue Dec 8, 2023 · 5 comments
Open

Conditionally exclude fields from Query #470

dvv opened this issue Dec 8, 2023 · 5 comments
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@dvv
Copy link

dvv commented Dec 8, 2023

Please consider adding an internal (exclude?) directive for any sort of fields. This should move the field out of Query/Mutation while keeping it available on deeper levels.

The default to be the scope's value.

This is mainly to housekeep the Query/Mutation clean while having all needed things in one exposed db schema.

@dvv dvv added the triage-required Pending triage from maintainers label Dec 8, 2023
@olirice olirice added enhancement New feature or request and removed triage-required Pending triage from maintainers labels Dec 8, 2023
@olirice
Copy link
Contributor

olirice commented Dec 11, 2023

As a rule we try to keep pg_graphql as configuration-free as possible

For excluding entities from insert/update/delete the best solution is to revoke insert/update/delete access from the relevant role.

I could see an argument for a comment directive to exclude it from the Query object though and it wouldn't be very invasive.

Will leave this open and mark as good first issue

@olirice olirice changed the title Conditionally exclude fields from Query/Mutation Conditionally exclude fields from Query Dec 11, 2023
@olirice olirice added the good first issue Good for newcomers label Dec 11, 2023
@dvv
Copy link
Author

dvv commented Dec 12, 2023

Well, revoking access does disable operations at db low-level as well. One has no option to disable access via graphql layer only, nope?

@Dmo16
Copy link

Dmo16 commented Dec 12, 2023

Being able to exclude tables from the schema is a logical feature, IMO. As @dvv mentioned, it isn't really feasible to restrict permissions on a table to the point where we can't interact with it.

My current use case that ties into this is that I need to extend my schema in a way that pg_graphql does not currently support.

To achieve this, I'm writing a small microservice with an edge function and stitching the endpoints together.

It would be nice to exclude the relevant tables from the pg_graphql schema so that I can expose them through this microservice as a modular unit.

I can, of course, handle type dupes and such in the stitching, but that creates more work than needed if I could simply decorate the table in Postgres to tell pg_graphql not to include it in the schema.

@FelixZY
Copy link

FelixZY commented Mar 16, 2024

In my case, I would like the user to be able to create entities and see the entity id field. However, I do not want users to be able to pick their own ids during creation/update. This would be much more explicit if I could remove the id field from the mutation type only.

@olirice
Copy link
Contributor

olirice commented Mar 19, 2024

@FelixZY for an id fields you can accomplish this by making that value a serial type or generated

in both of those cases the API excludes those fields from each table's insert and update types so your value is always generated by postgres rather than being provided by the user

I'll open an issue to add that info to the docs

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

No branches or pull requests

4 participants