Skip to content

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

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

cvas22 wants to merge 1 commit 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.

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

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 41 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

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: cf01bba5-e29b-4f9d-a2ca-c2b056d06f9d
Commits

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

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

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

1 participant