Skip to content

Commit

Permalink
Update graphql-apps.adoc
Browse files Browse the repository at this point in the history
  • Loading branch information
ujibang authored Nov 21, 2024
1 parent 7335025 commit 8cc97dd
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions docs/mongodb-graphql/graphql-apps.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,39 @@ type Query {
}
----

Starting with RESTHeart 8.2, the `@user` predefined argument is now available in aggregation stages when using Field-to-Aggregation mapping. This enables dynamic filtering based on the authenticated user. For example, the following mapping is supported:

```graphql
type User {
_id: String,
name: String
}

type Query {
me: User
}

# Mapping: 'me' always returns the authenticated user
"Query": {
"me": {
"db": "restheart",
"collection": "users",
"stages": [
{
"$match": {
"$or": [
{ "_id": { "$arg": ["@user._id", null] } },
{ "_id": { "$arg": ["@user.sub", null] } }
]
}
}
]
}
}
```

With this configuration, the `me` query will return the `User` object corresponding to the authenticated user.

==== Optional Stages

Field-to-aggregation mapping can include optional stages that are executed only when one or more arguments are specified. This feature enables the handling of optional GraphQL arguments.
Expand Down

0 comments on commit 8cc97dd

Please sign in to comment.