pg_graphql
pg_graphql copied to clipboard
Allow views to be queried via GQL
Summary
Make views available in the GQL schema so they can be queried.
Rationale
I have a view with some complex filtering not available via the GQL filter. I would like to be able to query this via GQL like a normal table rather than having to use supabase js.
Drawbacks
#69 I noticed that views were mentioned as being explicitly excluded in this issue so I presume that there are some drawbacks, but my SQL experience isn't enough to be aware of what these may be?
sorry for the slow response, I accidentally set my notifications to @mentions only!
Yes, views are definitely on the roadmap: The two things that make views tricky are:
- no primary key (pagination issue)
- no foreign keys (how to we connect them to the graph?)
For the primary key issue we could
- attempt to use pg_depends to detect it which will fail in complex uses
- force it to be specified manually in a comment directive
To connect views with the rest of the graph we could
- attempt to use pg_depends to detect it which will fail in complex uses
- force it to be specified manually in a comment directive
- use set returning functions to define relationships (how would pagination work in this case?)
I'm strongly opposed to using comments to control the GraphQL schema except where necessary so some more research into pg_depends is needed before we can make a decision
No problem! I didn't realise that views would have these extra complications so I can definitely understand why they aren't supported yet. Thank you for the detailed response!
@olirice any news on this? it will be a game changer and will open so many possibilities.
No progress yet but coming soon
There are 3 features remaining that I think are required to hit minimal feature-completeness
- globally unique id / select 1 record
- views
- exposing user defined functions
So I aim to get a version of those asap (next few months)
Would love some feedback on this thought:
One concern we've had with views is that they take on the role of the creator vs the role of the query-er, which is a security footgun because you're typically creating views with a superuser and superusers ignore row level security. In postgres 15 there is now an option for security barrier views which DO use the query user's role. I'm leaning towards making that setting mandatory for view exposed by pg_graphql.
- If RLS is off it should have no impact
- if RLS is on, you'll get the behavior a new user would expect
- its an easy migration for existing views
Other than restricting the feature to pg15, are there any downsides I'm missing?
Sounds good to me
We're moving to a graphql-focused approach, and would really love this feature!
Views would be awesome. Weve ended up heading towards using Graphql with Supabase and our existing db leverages RLS and views pretty heavily so there is a lot of data that just isnt able to be queried without view support. Glad to see this is on the roadmap and looking forward to any updates @olirice!
I expect the PR referenced above is going to merge tomorrow.
If anyone is interested in trying out this feature and providing feedback before the next official release (a few weeks out) please send me your project_ref and I'll have your supabase instance updated.
note that pre-release features may undergo breaking changes before they're released
I expect the PR referenced above is going to merge tomorrow.
If anyone is interested in trying out this feature and providing feedback before the next official release (a few weeks out) please send me your project_ref and I'll have your supabase instance updated.
note that pre-release features may undergo breaking changes before they're released
I'd like to check it out, thanks! dhticchigeuhvdgllosl
@olirice I'd be interested to test
zraxiuthzbhwgyjvapfq
Thanks!
I expect the PR referenced above is going to merge tomorrow.
If anyone is interested in trying out this feature and providing feedback before the next official release (a few weeks out) please send me your project_ref and I'll have your supabase instance updated.
note that pre-release features may undergo breaking changes before they're released
I'd love to try it out. I am currently using Supabase locally only, if I'm able to use the new release locally I'll definitely get it added and try to give feedback. Thank you for tacking on this ability! Huge add 💪🏼
@HTMHell dhticchigeuhvdgllosl has been updated
@DanielHritcu I don't see a project with ref zraxiuthzbhwgyjvapfq could you please double check that is correct?
The docs for how to use views aren't live yet because the release isn't out but you can see the instructions here https://github.com/supabase/pg_graphql/blob/master/docs/views.md
@olirice - Is this only available in a hosted Supabase environment? I tried following the installation process for this repo to get access to the views in my local dev environment but I couldn't seem to get it to work. Maybe I'm missing something obvious 🤷♂️ .
Appreciate your work on this!
Thanks!
Not yet
When features land on the platform the docs get updated so that's the best place to check to see what's currently available.
We've had a few features land in the last 2 weeks so I'll see about pushing a general off-cycle release this week unless there is significant feedback from testers