-
Notifications
You must be signed in to change notification settings - Fork 23
feat: Streamed list objects SDK support #244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3a3641a
feat: generate streamedlistobjects API layer from generator
SoulPancake aff7424
feat: streamed list objects support
SoulPancake cbc928e
feat: add example
SoulPancake 6a79981
fix: example code, deps
SoulPancake 02153f9
feat: standardise example code
SoulPancake be65362
feat: address coderabbit comment re init streamedlistobjectsapi
SoulPancake 86fcbc7
feat: address copilot comments
SoulPancake fde2193
fmt: apply spotless
SoulPancake c13c9b8
feat: add resource cleanup and try-catch
SoulPancake File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
|
|
||
|
|
||
| # StreamResultOfStreamedListObjectsResponse | ||
|
|
||
|
|
||
| ## Properties | ||
|
|
||
| | Name | Type | Description | Notes | | ||
| |------------ | ------------- | ------------- | -------------| | ||
| |**result** | [**StreamedListObjectsResponse**](StreamedListObjectsResponse.md) | | [optional] | | ||
| |**error** | [**Status**](Status.md) | | [optional] | | ||
|
|
||
|
|
||
|
|
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
|
|
||
|
|
||
| # StreamedListObjectsResponse | ||
|
|
||
| The response for a StreamedListObjects RPC. | ||
|
|
||
| ## Properties | ||
|
|
||
| | Name | Type | Description | Notes | | ||
| |------------ | ------------- | ------------- | -------------| | ||
| |**_object** | **String** | | | | ||
|
|
||
|
|
||
|
|
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| # OpenFGA Configuration (REQUIRED) | ||
| FGA_API_URL=http://localhost:8080 | ||
| FGA_STORE_ID=store_id_here | ||
| FGA_MODEL_ID=model_id_here | ||
|
|
||
| # Authentication (optional - for authenticated OpenFGA instances) | ||
| FGA_CLIENT_ID=client_id_here | ||
| FGA_CLIENT_SECRET=client_secret_here | ||
| FGA_API_AUDIENCE=api_audience_here | ||
| FGA_API_TOKEN_ISSUER=api_issuer_here | ||
|
|
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| .PHONY: all build run run-openfga | ||
|
|
||
| all: build | ||
|
|
||
| openfga_version=latest | ||
|
|
||
| build: | ||
| ./gradlew build | ||
|
|
||
| run: | ||
| ./gradlew run | ||
|
|
||
| run-openfga: | ||
| docker pull docker.io/openfga/openfga:${openfga_version} && \ | ||
| docker run -p 8080:8080 docker.io/openfga/openfga:${openfga_version} run | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| # Streamed List Objects Example | ||
|
|
||
| This example demonstrates working with [OpenFGA's `/streamed-list-objects` endpoint](https://openfga.dev/api/service#/Relationship%20Queries/StreamedListObjects) using the Java SDK's `streamedListObjects()` method. | ||
|
|
||
| ## What is Streamed ListObjects? | ||
|
|
||
| The StreamedListObjects API is similar to the regular ListObjects API, but with key differences: | ||
|
|
||
| 1. **Streaming Response**: Instead of collecting all objects before returning a response, it streams them to the client as they are collected | ||
| 2. **No Result Limit**: The number of results returned is only limited by the execution timeout specified in the server configuration (`OPENFGA_LIST_OBJECTS_DEADLINE`) | ||
| 3. **Immediate Processing**: You can start processing results as they arrive, without waiting for the entire result set | ||
|
|
||
| ## When to Use Streamed ListObjects | ||
|
|
||
| Use the Streamed ListObjects API when: | ||
|
|
||
| - You expect a large number of results that would take a long time to collect | ||
| - You want to start processing results immediately rather than waiting for the complete set | ||
| - You might not need all results (e.g., you want to stop after finding a certain number) | ||
| - You want to avoid timeout issues with very large result sets | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - Java 11+ | ||
| - OpenFGA running on `localhost:8080` | ||
|
|
||
| You can start OpenFGA with Docker by running the following command: | ||
|
|
||
| ```bash | ||
| docker pull openfga/openfga && docker run -it --rm -p 8080:8080 openfga/openfga run | ||
| ``` | ||
|
|
||
| ## Running the Example | ||
|
|
||
| No additional setup is required to run this example. Simply run the following command: | ||
|
|
||
| ```bash | ||
| make run | ||
| ``` | ||
|
|
||
| ### Environment Variables (Optional) | ||
|
|
||
| For authenticated OpenFGA instances, set the following environment variables: | ||
|
|
||
| ```bash | ||
| export FGA_API_URL=http://localhost:8080 # Your OpenFGA server URL | ||
| export FGA_CLIENT_ID=your_client_id | ||
| export FGA_CLIENT_SECRET=your_client_secret | ||
| export FGA_API_TOKEN_ISSUER=your_token_issuer | ||
| export FGA_API_AUDIENCE=your_audience | ||
| ``` | ||
|
|
||
| ## Code Examples | ||
|
|
||
| ### Basic Usage | ||
|
|
||
| ```java | ||
| // Create a request | ||
| var request = new ClientListObjectsRequest() | ||
| .type("document") | ||
SoulPancake marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| .relation("owner") | ||
| .user("user:anne"); | ||
|
|
||
| // Call the streaming API and ensure proper resource cleanup | ||
| try (var objectStream = fgaClient.streamedListObjects(request).get()) { | ||
| // Collect all results | ||
| List<String> objects = objectStream | ||
| .map(StreamedListObjectsResponse::getObject) | ||
| .collect(Collectors.toList()); | ||
| } | ||
| ``` | ||
|
|
||
| ### Early Termination | ||
|
|
||
| ```java | ||
| // Get only the first 10 results, ensuring the stream is closed properly | ||
| try (var objectStream = fgaClient.streamedListObjects(request).get()) { | ||
| List<String> firstTen = objectStream | ||
| .map(StreamedListObjectsResponse::getObject) | ||
| .limit(10) | ||
| .collect(Collectors.toList()); | ||
| } | ||
| ``` | ||
|
|
||
| ### Process as You Go | ||
|
|
||
| ```java | ||
| // Process each object immediately as it arrives | ||
| try (var objectStream = fgaClient.streamedListObjects(request).get()) { | ||
| objectStream | ||
| .map(StreamedListObjectsResponse::getObject) | ||
| .forEach(obj -> { | ||
| // Do something with each object | ||
| System.out.println("Processing: " + obj); | ||
| }); | ||
| } | ||
| ``` | ||
|
|
||
| ### With Options | ||
|
|
||
| ```java | ||
| // Use options to specify consistency preference | ||
| var options = new ClientListObjectsOptions() | ||
| .consistency(ConsistencyPreference.HIGHER_CONSISTENCY) | ||
| .authorizationModelId("01GXSXXXXXXXXXXXXXXXX"); | ||
|
|
||
| var objectStream = fgaClient.streamedListObjects(request, options).get(); | ||
| ``` | ||
|
|
||
| ## Comparison with Regular ListObjects | ||
|
|
||
| | Feature | ListObjects | Streamed ListObjects | | ||
| |---------|-------------|---------------------| | ||
| | Result Collection | Waits for all results | Streams results as computed | | ||
| | Result Limit | Limited by server pagination | Limited only by execution timeout | | ||
| | Processing | Must wait for complete response | Can process immediately | | ||
| | Use Case | Small to medium result sets | Large result sets, immediate processing | | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.