Comments (2)
without RLS
I hate to be the bearer of bad news but avoiding RLS is highly likely to make your app less secure and more complex
in a typical postgraphile app, the solution to this feature is usually a currentUser
query which is defined by a few postgres functions
create function app_public.current_session_id() returns uuid as $$
select nullif(pg_catalog.current_setting('jwt.claims.session_id', true), '')::uuid;
$$ language sql stable;
create function app_public.current_user() returns app_public.users as $$
select users.* from app_public.users where id = app_public.current_user_id();
$$ language sql stable;
then assuming that orders
has a foreign key to users
you can access the current user's orders with a graphql query like
query {
currentUser {
orders {
nodes {
id
amount
}
}
}
}
from crystal.
^ This is the correct answer, thanks Daniel.
Basically: you use the graph-based nature of GraphQL to start at the current user, and then navigate from there to the related orders. You can add a field representing the current user via a database function as Daniel shows, or you can use makeExtendSchemaPlugin
along with additionalGraphQLContextFromRequest
(v4) or preset.grafast.context
(v5) to add the relevant user ID to the context
so that it can be used in your resolver (v4) / plan resolver (v5).
If you're really set on not using RLS at all (which I don't think is your question, but just in case), check out https://github.com/benjie/v5-auth-poc which is V5 only and highly experimental (not supported at all - it even needs a patch (included) to work currently).
[semi-automated message] To keep things manageable I'm going to close this issue as I think it's solved; but if not or you require further help please re-open it.
from crystal.
Related Issues (20)
- `makeWrapPlansAfterArgumentsHaveBeenAppliedPlugin` - solve confusion
- PostGraphileRelayPreset bug: mutation with "null" foreign key value does not work (returns null) HOT 1
- How does Postgraphile integrate with Apache AGE? HOT 1
- Polymorphism - union containing members of an interface plus another; how to plan?
- Create tests for middleware system (grafast, grafserv)
- multi tenancy and update pg schema without restart HOT 1
- Koa middleware does not call next() for all scenarios HOT 7
- (v5) I'd like get a generic executor from `build.input.pgRegistry` inside a `makeExtendSchemaPlugin`. HOT 1
- Questions based on initial experience with v5 polymorphism HOT 6
- The v5 documentation for crud mutations mentions both `insert` and `create` as values for the `@behavior` smart tag. HOT 2
- PgExecutor cache is not cleared between subscription payloads
- Subscription error causes socket to disconnect
- `PostGraphileRelayPreset` does not eliminate `Row` in `ByRowId`
- Polymorphic types offer mutations under some circumstances? HOT 1
- Derived types include selector for the derived types when using relational polymorphism
- How to call custom function with the id provided by the relay preset HOT 3
- It should be possible to declare a shared `@ref` only in the base table when using relational polymporphism HOT 2
- Using `makeWrapPlansPlugin` creates an error when exporting the schema HOT 1
- TypeScript regression: loadOne no longer inferring types HOT 1
- Documentation for `makePgService({adaptorSettings})` appear to be outdated
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from crystal.