pg_graphql icon indicating copy to clipboard operation
pg_graphql copied to clipboard

Allow views to be queried via GQL

Open Flambe opened this issue 3 years ago • 2 comments

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?

Flambe avatar Aug 18 '22 09:08 Flambe

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

olirice avatar Aug 25 '22 13:08 olirice

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!

Flambe avatar Aug 25 '22 19:08 Flambe

@olirice any news on this? it will be a game changer and will open so many possibilities.

HTMHell avatar Oct 24 '22 20:10 HTMHell

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)

olirice avatar Oct 24 '22 22:10 olirice

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?

olirice avatar Oct 24 '22 22:10 olirice

Sounds good to me

HTMHell avatar Oct 24 '22 22:10 HTMHell

We're moving to a graphql-focused approach, and would really love this feature!

Marviel avatar Dec 21 '22 17:12 Marviel

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!

drewbietron avatar Dec 26 '22 22:12 drewbietron

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

olirice avatar Jan 10 '23 20:01 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'd like to check it out, thanks! dhticchigeuhvdgllosl

HTMHell avatar Jan 10 '23 21:01 HTMHell

@olirice I'd be interested to test

zraxiuthzbhwgyjvapfq

Thanks!

ghost avatar Jan 10 '23 23:01 ghost

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 💪🏼

drewbietron avatar Jan 11 '23 14:01 drewbietron

@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 avatar Jan 11 '23 15:01 olirice

@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!

drewbietron avatar Jan 14 '23 17:01 drewbietron

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

olirice avatar Jan 14 '23 17:01 olirice