graphile / graphile/graphile.github.io
Recipe: Creating a viewer/"logged in user" root field
- 主要言語
- SCSS
- スター
- 27
- フォーク
- 126
- PR マージ指標
- 30日以内にマージされた PR はありません
説明
Here's another proposal for a very simple recipe. Again, feel free to do what you want with this.
## Creating a viewer/"logged in user" root field
A lot of API:s use the "viewer" convention, putting a field on the root query that references the currently logged in user. If you have your authentication set up properly and a have a way of getting the currently logged in user's user id, you can do this very easily with Postgraphile:
```sql
create function my_schema.viewer()
returns my_schema.users as $$
select *
from my_schema.users
where id = current_user_id(); /* current_user_id is a function that returns the logged in user's id, usually by extracting it from the auth token used */
$$ language sql stable;
```
This will put a field (viewer) on your root query that returns the logged in user. Very convenient! Check out the docs on security for handling authorization and adding a current_user_id function.
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
調査の方向性
Review this proposal alongside the existing security documentation it references and the site's current recipe organization. Add a recipe explaining the viewer root field, including the shown SQL pattern and its authentication assumptions; done means the recipe is published in the appropriate documentation location and links to the relevant security guidance.
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- graphql, sql
- 領域
- documentation
- issue の種類
- ドキュメント
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 45/100