Skip to content

Commit

Permalink
feat(docs): add SDKs to BatchCheckViewer (#950)
Browse files Browse the repository at this point in the history
  • Loading branch information
rhamzeh authored Feb 4, 2025
1 parent d3f791f commit a16190e
Show file tree
Hide file tree
Showing 4 changed files with 336 additions and 18 deletions.
22 changes: 15 additions & 7 deletions docs/content/getting-started/perform-check.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -169,16 +169,28 @@ The result's `allowed` field will return `true` if the relationship exists and `

If you want to check multiple user-object-relationship combinations in a single request, you can use the [Batch Check](/api/service#Relationship%20Queries/BatchCheck) API endpoint. Batching authorization checks together in a single request significantly reduces overall network latency.

The Batch Check endpoint requires a `correlation_id` parameter for each check. The `correlation_id` is used to "correlate" the check responses with the checks sent in the request, since `tuple_keys` and `contextual_tuples` are not returned in the response on purpose to reduce data transfer to improve network latency. A `correlation_id` can be composed of any string of alphanumeric characters or dashes between 1-36 characters in length.
:::note
The BatchCheck endpoint is currently only supported by the JS SDK (>=[v0.8.0](https://github.com/openfga/js-sdk/releases/tag/v0.8.0) and the Python SDK (>=[v0.9.0](https://github.com/openfga/python-sdk/releases/tag/v0.9.0)). Support in the other SDKs is being worked on.

In the SDKs that don't support the server-side `BatchCheck`, the `BatchCheck` method performs client-side batch checks by making multiple check requests with limited parallelization, in SDK versions that do support the server-side `BatchCheck`, the existing method has been renamed to `ClientBatchCheck`.

Refer to the README for each SDK for more information. Refer to the release notes of the relevant SDK version for more information on how to migrate from client-side to the server-side `BatchCheck`.
:::

The BatchCheck endpoint requires a `correlation_id` parameter for each check. The `correlation_id` is used to "correlate" the check responses with the checks sent in the request, since `tuple_keys` and `contextual_tuples` are not returned in the response on purpose to reduce data transfer to improve network latency. A `correlation_id` can be composed of any string of alphanumeric characters or dashes between 1-36 characters in length.
This means you can use:
- simple iterating integers `1,2,3,etc`
- UUID `e5fe049b-f252-40b3-b795-fe485d588279`
- ULID `01JBMD9YG0XH3B4GVA8A9D2PSN`
- or some other unique string

But each `correlation_id` within a request must be unique.
Each `correlation_id` within a request must be unique.

*Note*: If you are using one of our SDKs, the `correlation_id` is inserted for you by default and automatically correlates the `allowed` response with the proper `tuple_key`.
:::note
If you are using one of our SDKs:
* the `correlation_id` is inserted for you by default and automatically correlates the `allowed` response with the proper `tuple_key`
* if you pass in more checks than the server supports in a single call (default `50`, configurable on the server), the SDK will automatically split and batch the `BatchCheck` requests for you, how it does this can be configured using the `maxBatchSize` and `maxParallelRequests` options in the SDK.
:::

To check whether user `user:anne` has multiple relationships `writer` and `reader` with object `document:Z`

Expand All @@ -199,11 +211,7 @@ To check whether user `user:anne` has multiple relationships `writer` and `reade
allowed: true
}
]}

skipSetup={true}
allowedLanguages={[
SupportedLanguage.CURL,
]}
/>

The result will include an `allowed` field for each authorization check that will return `true` if the relationship exists and `false` if the relationship does not exist.
Expand Down
4 changes: 3 additions & 1 deletion docs/content/interacting/relationship-queries.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,9 @@ The <ProductName format={ProductNameFormat.ShortForm}/> API will return `true` d

### Caveats and when not to use it

If you are making less than 10 checks, it may be faster to call the [Check API](/api/service#Relationship%20Queries/Check) in parallel instead of Batch Check.
If you are making less than 10 checks, it may be faster to call the [Check API](/api/service#Relationship%20Queries/Check) in parallel instead of Batch Check.

The new BatchCheck endpoint is currently supported by the JS SDK (>=[v0.8.0](https://github.com/openfga/js-sdk/releases/tag/v0.8.0) and the Python SDK (>=[v0.9.0](https://github.com/openfga/python-sdk/releases/tag/v0.9.0)). Support in the other SDKs is being worked on.

## Read

Expand Down
Loading

0 comments on commit a16190e

Please sign in to comment.