Skip to content

feat: allow overriding the store ID per request - #409

Open
cvas22 wants to merge 2 commits into
openfga:mainfrom
cvas22:feat/150-store-id-per-request
Open

cvas22 wants to merge 2 commits into
openfga:mainfrom
cvas22:feat/150-store-id-per-request

Conversation

@cvas22

@cvas22 cvas22 commented Nov 5, 2026 •

Copy link
Copy Markdown

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 calling setStoreId before each request.

var options = new ClientCheckOptions()
    .storeId("01HVMMBCMGZNT3SED4Z17ECXCA");
fgaClient.check(request, options).get();

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().
  • README: the Check example shows the option. The template change is in chore(docs): document the per-request store ID in the Java SDK README sdk-generator#746.

Nothing changes for callers that don't set the option.

Fixes #150

Testing

New OpenFgaClientStoreIdOverrideTest (WireMock):

  • 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.

Fixes openfga#150

Signed-off-by: Srinivas Chippagiri <cvas22@gmail.com>
@coderabbitai

coderabbitai Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

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.

Changes

Per-request store selection

Layer / File(s) Summary
Request option IDs
src/main/java/dev/openfga/sdk/api/configuration/Client*Options.java, src/main/java/dev/openfga/sdk/api/client/model/ClientStreamedListObjectsOptions.java
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.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Feature

Sequence Diagram(s)

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: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed 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 Passed 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 Passed 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.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 24cc9ffe-9b22-4436-be7b-e3bac1db9b00
Commits

Reviewing files that changed from the base of the PR and between bc745c9 and e717ebb.

Files selected for processing: 24

  • README.md
  • src/main/java/dev/openfga/sdk/api/client/OpenFgaClient.java
  • src/main/java/dev/openfga/sdk/api/client/model/ClientStreamedListObjectsOptions.java
  • src/main/java/dev/openfga/sdk/api/configuration/ClientBatchCheckClientOptions.java
  • src/main/java/dev/openfga/sdk/api/configuration/ClientBatchCheckOptions.java
  • src/main/java/dev/openfga/sdk/api/configuration/ClientCheckOptions.java
  • src/main/java/dev/openfga/sdk/api/configuration/ClientDeleteStoreOptions.java
  • src/main/java/dev/openfga/sdk/api/configuration/ClientDeleteTuplesOptions.java
  • src/main/java/dev/openfga/sdk/api/configuration/ClientExpandOptions.java
  • src/main/java/dev/openfga/sdk/api/configuration/ClientGetStoreOptions.java
  • src/main/java/dev/openfga/sdk/api/configuration/ClientListObjectsOptions.java
  • src/main/java/dev/openfga/sdk/api/configuration/ClientListRelationsOptions.java
  • src/main/java/dev/openfga/sdk/api/configuration/ClientListUsersOptions.java
  • src/main/java/dev/openfga/sdk/api/configuration/ClientReadAssertionsOptions.java
  • src/main/java/dev/openfga/sdk/api/configuration/ClientReadAuthorizationModelOptions.java
  • src/main/java/dev/openfga/sdk/api/configuration/ClientReadAuthorizationModelsOptions.java
  • src/main/java/dev/openfga/sdk/api/configuration/ClientReadChangesOptions.java
  • src/main/java/dev/openfga/sdk/api/configuration/ClientReadLatestAuthorizationModelOptions.java
  • src/main/java/dev/openfga/sdk/api/configuration/ClientReadOptions.java
  • src/main/java/dev/openfga/sdk/api/configuration/ClientWriteAssertionsOptions.java
  • src/main/java/dev/openfga/sdk/api/configuration/ClientWriteAuthorizationModelOptions.java
  • src/main/java/dev/openfga/sdk/api/configuration/ClientWriteOptions.java
  • src/main/java/dev/openfga/sdk/api/configuration/ClientWriteTuplesOptions.java
  • src/test/java/dev/openfga/sdk/api/client/OpenFgaClientStoreIdOverrideTest.java

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@cvas22

cvas22 commented Nov 20, 2026

Copy link
Copy Markdown
Author

@SoulPancake when you have time, could you have a look? thx

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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.

1 open issue
What changed in this PR

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.
File Description
src/​test/​java/​dev/​openfga/​sdk/​api/​client/​OpenFgaClientStoreIdOverrideTest.java Tests overrides, fallback, missing-store validation, and delegated checks.
src/​main/​java/​dev/​openfga/​sdk/​api/​configuration/​ClientWriteTuplesOptions.java Adds store selection for tuple writes.
src/​main/​java/​dev/​openfga/​sdk/​api/​configuration/​ClientWriteOptions.java Adds store selection for writes.
src/​main/​java/​dev/​openfga/​sdk/​api/​configuration/​ClientWriteAuthorizationModelOptions.java Adds store selection for model creation.
src/​main/​java/​dev/​openfga/​sdk/​api/​configuration/​ClientWriteAssertionsOptions.java Adds store selection for assertion writes.
src/​main/​java/​dev/​openfga/​sdk/​api/​configuration/​ClientReadOptions.java Adds store selection for tuple reads.
src/​main/​java/​dev/​openfga/​sdk/​api/​configuration/​ClientReadLatestAuthorizationModelOptions.java Adds store selection for latest-model reads.
src/​main/​java/​dev/​openfga/​sdk/​api/​configuration/​ClientReadChangesOptions.java Adds store selection for change reads.
src/​main/​java/​dev/​openfga/​sdk/​api/​configuration/​ClientReadAuthorizationModelsOptions.java Adds store selection for model listing.
src/​main/​java/​dev/​openfga/​sdk/​api/​configuration/​ClientReadAuthorizationModelOptions.java Adds store selection for model reads.
src/​main/​java/​dev/​openfga/​sdk/​api/​configuration/​ClientReadAssertionsOptions.java Adds store selection for assertion reads.
src/​main/​java/​dev/​openfga/​sdk/​api/​configuration/​ClientListUsersOptions.java Adds store selection for user listing.
src/​main/​java/​dev/​openfga/​sdk/​api/​configuration/​ClientListRelationsOptions.java Adds and forwards store selection to delegated checks.
src/​main/​java/​dev/​openfga/​sdk/​api/​configuration/​ClientListObjectsOptions.java Adds store selection for object listing.
src/​main/​java/​dev/​openfga/​sdk/​api/​configuration/​ClientGetStoreOptions.java Adds store selection for store retrieval.
src/​main/​java/​dev/​openfga/​sdk/​api/​configuration/​ClientExpandOptions.java Adds store selection for expansion.
src/​main/​java/​dev/​openfga/​sdk/​api/​configuration/​ClientDeleteTuplesOptions.java Adds store selection for tuple deletion.
src/​main/​java/​dev/​openfga/​sdk/​api/​configuration/​ClientDeleteStoreOptions.java Adds store selection for store deletion.
src/​main/​java/​dev/​openfga/​sdk/​api/​configuration/​ClientCheckOptions.java Adds store selection for permission checks.
src/​main/​java/​dev/​openfga/​sdk/​api/​configuration/​ClientBatchCheckOptions.java Adds store selection for server-side batch checks.
src/​main/​java/​dev/​openfga/​sdk/​api/​configuration/​ClientBatchCheckClientOptions.java Adds and forwards store selection to individual checks.
src/​main/​java/​dev/​openfga/​sdk/​api/​client/​OpenFgaClient.java Resolves overrides and routes store-scoped requests.
src/​main/​java/​dev/​openfga/​sdk/​api/​client/​model/​ClientStreamedListObjectsOptions.java Adds store selection for streamed object listing.
README.md Demonstrates the store override in the Check example.

Review effort: Balanced

List<ClientTupleKey> tupleKeys, ClientWriteTuplesOptions options) throws FgaInvalidParameterException {
configuration.assertValid();
String storeId = configuration.getStoreIdChecked();
String storeId = getStoreIdChecked(options != null ? options.getStoreId() : null);

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow setting Store Id per request for multi tenant implementations

2 participants