You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat: allow overriding the store ID per request - #409
Adds a per-request store ID override to the Java SDK (#150), as the Go, .NET and JS SDKs have. With it, a multi-tenant application can use one OpenFgaClient, and so one connection pool, for all its stores instead of creating a client per store or calling setStoreId before each request.
Changes, following the pattern from @jimmyjames's example commit in the issue (ef91a07):
A storeId option (fluent setter and getter) on the options of every client method that works on a store: get/delete store, the authorization model methods, read changes, read, write, write/delete tuples, check, client batch check, batch check, expand, list objects, streamed list objects, list relations, list users, and the assertion methods.
OpenFgaClient resolves the store with a private getStoreIdChecked(String) helper: the option when it's set, otherwise the configured store ID. A missing store ID still fails with the same FgaInvalidParameterException. batchCheck now uses the resolved store ID instead of reading configuration.getStoreId() inside the request lambda.
clientBatchCheck and listRelations pass the store ID on to their individual checks, through asClientCheckOptions() and asClientBatchCheckClientOptions().
without the option, requests go to the configured store
check, write, read, listObjects, batchCheck and streamedListObjects go to the store from the options
listRelations sends all its checks to the store from the options
the option works when no store is configured, and a missing store ID in both places still throws
I haven't run the Gradle build locally, so I'm relying on CI for compilation and the test run.
Notes
@joarobles offered to take this in February 2025. Since there's been no PR since then, I went ahead; happy to coordinate if you're still working on it.
Summary by CodeRabbit
New Features
Specify a store per request across client operations, overriding the configured store. Requests without an override continue to use the configured store.
Set an authorization model ID per tuple write or delete request, overriding the configured value.
Use one client to work with multiple stores; the README includes an updated example.
Add a storeId option to the options of every OpenFgaClient method that
works on a store. When it is set, the request goes to that store instead
of the one in the client configuration, so one client and its connection
pool can serve several stores. clientBatchCheck and listRelations pass it
on to their checks.
Fixesopenfga#150
Signed-off-by: Srinivas Chippagiri <cvas22@gmail.com>
No actionable comments were generated in the recent review.
Walkthrough
Request options now accept a per-request store ID across client operations. OpenFgaClient uses a nonblank request override or falls back to the configured store ID. Tuple write and delete options also accept authorization model ID overrides. Tests and the README example cover this behavior.
Request options add fluent store ID setters and getters. Tuple write and delete options also add authorization model ID options. Batch option conversions copy the store ID.
ID resolution and request routing src/main/java/dev/openfga/sdk/api/client/OpenFgaClient.java
Client operations use a nonblank request store ID or fall back to the configured store ID. Tuple write and delete operations also resolve the authorization model ID. Batch requests use the resolved store ID.
Examples and routing tests README.md, src/test/java/dev/openfga/sdk/api/client/OpenFgaClientStoreIdOverrideTest.java
The README check example demonstrates the store override. WireMock tests cover fallback, overrides, missing store IDs, request routing, and tuple authorization model ID selection.
sequenceDiagram
participant Caller
participant ClientCheckOptions
participant OpenFgaClient
participant OpenFgaAPI
Caller->>ClientCheckOptions: Set request storeId
Caller->>OpenFgaClient: Submit check and options
OpenFgaClient->>OpenFgaClient: Resolve override or configured storeId
OpenFgaClient->>OpenFgaAPI: Send check to resolved store
Loading
Suggested reviewers: rhamzeh, booniepepper
Merge Risk: Minimal · up to e717e
This adds an optional per-request store ID and keeps the existing behavior for callers that do not use it. No merge-blocking risk was found, though the build and tests have not been run locally.
Pre-merge checks: 4
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title "feat: allow overriding the store ID per request" matches the main change. The PR adds a per-request storeId option to OpenFgaClient methods and option classes, so callers can use one client…
Linked Issues check
Directly linked issue #150 requires a per-request store ID option so one OpenFgaClient can serve multiple stores. The PR meets this from the whole-PR summary (base bc745c9, head e717ebb). ClientCheckO…
Out of Scope Changes check
All changes support the store override objective of #150. The option classes, the OpenFgaClient resolution logic, the batch-check and listRelations propagation, the README Check example, and the WireM…
Full details: Title check
Explanation
The title "feat: allow overriding the store ID per request" matches the main change. The PR adds a per-request storeId option to OpenFgaClient methods and option classes, so callers can use one client across stores. The title is specific, short, and follows the conventional-commit style. The later authorizationModelId override commit is a minor secondary change that the title does not mention, which is expected.
Full details: Linked Issues check
Explanation
Directly linked issue #150 requires a per-request store ID option so one OpenFgaClient can serve multiple stores. The PR meets this from the whole-PR summary (base bc745c9, head e717ebb). ClientCheckOptions gains storeId(String) and getStoreId(), matching the issue example. OpenFgaClient resolves the store through a private getStoreIdChecked(String) helper: the per-request option is used when set, otherwise the configured store ID. A missing ID in both places still throws FgaInvalidParameterException. The same option is added to the other store-scoped option classes (get/delete store, authorization models, read changes, read, write, tuple write/delete, check, batch check, expand, list objects, streamed list objects, list relations, list users, assertions). clientBatchCheck and listRelations pass the resolved store ID to their individual checks through asClientCheckOptions() and asClientBatchCheckClientOptions(). New OpenFgaClientStoreIdOverrideTest (WireMock) covers the fallback, the per-method overrides, the listRelations propagation, and the no-configured-store case. Limits: the diff hunks were not read directly, and the build and tests were not run, so compilation and test results rest on the summary and CI.
Full details: Out of Scope Changes check
Explanation
All changes support the store override objective of #150. The option classes, the OpenFgaClient resolution logic, the batch-check and listRelations propagation, the README Check example, and the WireMock test class all fall within that objective. The later commit that adds authorizationModelId overrides to writeTuples and deleteTuples (ClientWriteTuplesOptions and ClientDeleteTuplesOptions) is a supporting change. Its commit message states that a store override can pair with a configured model ID from another store, so this option is needed for the per-request store to work correctly. It adds public surface, but it does not change behavior for callers that do not set the options. No unrelated change was identified in the summary. The source diff was not read directly, so this verdict rests on the summary.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The writeTuples helper sends the configured authorization model ID even when the store is overridden, causing cross-store requests to fail without an option to select the target store’s model.
Adds per-request store selection to the Java SDK, addressing #150 so multi-tenant applications can share one OpenFgaClient and connection pool without changing the configured store between requests.
Changes:
Adds fluent storeId options to store-scoped operations.
Resolves request overrides before the configured store and forwards them through client-side checks.
Adds WireMock routing tests and documents the option in the README.
The reason will be displayed to describe this comment to others. Learn more.
ClientWriteTuplesOptions and ClientDeleteTuplesOptions both take an authorizationModelId now, and it wins over the configured one. Pushed in e717ebb with a test that overrides store and model together.
With a store override, the configured model ID may belong to another store,
so both helpers now take an authorizationModelId option that wins over the
configured one.
Signed-off-by: Srinivas Chippagiri <cvas22@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds a per-request store ID override to the Java SDK (#150), as the Go, .NET and JS SDKs have. With it, a multi-tenant application can use one
OpenFgaClient, and so one connection pool, for all its stores instead of creating a client per store or callingsetStoreIdbefore each request.Changes, following the pattern from @jimmyjames's example commit in the issue (ef91a07):
storeIdoption (fluent setter and getter) on the options of every client method that works on a store: get/delete store, the authorization model methods, read changes, read, write, write/delete tuples, check, client batch check, batch check, expand, list objects, streamed list objects, list relations, list users, and the assertion methods.OpenFgaClientresolves the store with a privategetStoreIdChecked(String)helper: the option when it's set, otherwise the configured store ID. A missing store ID still fails with the sameFgaInvalidParameterException.batchChecknow uses the resolved store ID instead of readingconfiguration.getStoreId()inside the request lambda.clientBatchCheckandlistRelationspass the store ID on to their individual checks, throughasClientCheckOptions()andasClientBatchCheckClientOptions().Nothing changes for callers that don't set the option.
Fixes #150
Testing
New
OpenFgaClientStoreIdOverrideTest(WireMock):check,write,read,listObjects,batchCheckandstreamedListObjectsgo to the store from the optionslistRelationssends all its checks to the store from the optionsI haven't run the Gradle build locally, so I'm relying on CI for compilation and the test run.
Notes
@joarobles offered to take this in February 2025. Since there's been no PR since then, I went ahead; happy to coordinate if you're still working on it.
Summary by CodeRabbit