Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- feat: add generic `ToPtr[T any](v T) *T` function for creating pointers to any type
- deprecation: `PtrBool`, `PtrInt`, `PtrInt32`, `PtrInt64`, `PtrFloat32`, `PtrFloat64`, `PtrString`, and `PtrTime` are now deprecated in favor of the generic `ToPtr` function
- chore: add a top-level makefile in go-sdk to simplify running tests and linters: (#250)
- feat: add support for StreamedListObjects endpoint (#271)

## v0.7.3

Expand Down
46 changes: 46 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ This is an autogenerated Go SDK for OpenFGA. It provides a wrapper around the [O
- [Batch Check](#batch-check)
- [Expand](#expand)
- [List Objects](#list-objects)
- [Streamed List Objects](#streamed-list-objects)
- [List Relations](#list-relations)
- [List Users](#list-users)
- [Assertions](#assertions)
Expand Down Expand Up @@ -912,6 +913,51 @@ data, err := fgaClient.ListObjects(context.Background()).

// data.Objects = ["document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a"]
```

##### Streamed List Objects

List objects of a particular type that the user has access to, using the streaming API.

The Streamed ListObjects API is very similar to the ListObjects API, with two key differences:
1. **Streaming Results**: Instead of collecting all objects before returning a response, it streams them to the client as they are collected.
2. **No Pagination Limit**: Returns all results without the 1000-object limit of the standard ListObjects API.

This is particularly useful when querying **computed relations** that may return large result sets.

[API Documentation](https://openfga.dev/api/service#/Relationship%20Queries/StreamedListObjects)

```golang
options := ClientStreamedListObjectsOptions{
// You can rely on the model id set in the configuration or override it for this specific request
AuthorizationModelId: openfga.PtrString("01GAHCE4YVKPQEKZQHT2R89MQV"),
}

body := ClientStreamedListObjectsRequest{
User: "user:anne",
Relation: "can_read",
Type: "document",
}

response, err := fgaClient.StreamedListObjects(context.Background()).Body(body).Options(options).Execute()
if err != nil {
// .. Handle error
}
defer response.Close()

// Consume objects from the stream
var objects []string
for obj := range response.Objects {
objects = append(objects, obj.Object)
}

// Check for any errors during streaming
if err := <-response.Errors; err != nil {
// .. Handle streaming error
}

// objects = ["document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a"]
```

#### List Relations

List the relations a user has on an object.
Expand Down
19 changes: 16 additions & 3 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,19 @@ type SdkClient interface {
*/
ListUsersExecute(r SdkClientListUsersRequestInterface) (*ClientListUsersResponse, error)

/*
* StreamedListObjects Stream all objects of the given type that the user has a relation with
* @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
* @return SdkClientStreamedListObjectsRequestInterface
*/
StreamedListObjects(ctx _context.Context) SdkClientStreamedListObjectsRequestInterface

/*
* StreamedListObjectsExecute executes the StreamedListObjects request and returns a channel
* @return *ClientStreamedListObjectsResponse
*/
StreamedListObjectsExecute(request SdkClientStreamedListObjectsRequestInterface) (*ClientStreamedListObjectsResponse, error)

/* Assertions */

/*
Expand Down Expand Up @@ -3340,7 +3353,7 @@ func (r *ClientStreamedListObjectsResponse) Close() {
}
}

func (client *OpenFgaClient) streamedListObjects(ctx _context.Context) SdkClientStreamedListObjectsRequestInterface {
func (client *OpenFgaClient) StreamedListObjects(ctx _context.Context) SdkClientStreamedListObjectsRequestInterface {
return &SdkClientStreamedListObjectsRequest{
Client: client,
ctx: ctx,
Expand Down Expand Up @@ -3372,7 +3385,7 @@ func (request *SdkClientStreamedListObjectsRequest) Body(body ClientStreamedList
}

func (request *SdkClientStreamedListObjectsRequest) Execute() (*ClientStreamedListObjectsResponse, error) {
return request.Client.streamedListObjectsExecute(request)
return request.Client.StreamedListObjectsExecute(request)
}

func (request *SdkClientStreamedListObjectsRequest) GetContext() _context.Context {
Expand All @@ -3387,7 +3400,7 @@ func (request *SdkClientStreamedListObjectsRequest) GetOptions() *ClientStreamed
return request.options
}

func (client *OpenFgaClient) streamedListObjectsExecute(request SdkClientStreamedListObjectsRequestInterface) (*ClientStreamedListObjectsResponse, error) {
func (client *OpenFgaClient) StreamedListObjectsExecute(request SdkClientStreamedListObjectsRequestInterface) (*ClientStreamedListObjectsResponse, error) {
if request.GetBody() == nil {
return nil, FgaRequiredParamError{param: "body"}
}
Expand Down
12 changes: 6 additions & 6 deletions client/streaming_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func TestClientStreamedListObjects_Success(t *testing.T) {

ctx := context.Background()

response, err := client.streamedListObjects(ctx).
response, err := client.StreamedListObjects(ctx).
Body(ClientStreamedListObjectsRequest{
Type: "document",
Relation: "viewer",
Expand Down Expand Up @@ -115,7 +115,7 @@ func TestClientStreamedListObjects_WithOptions(t *testing.T) {
ctx := context.Background()
consistency := openfga.CONSISTENCYPREFERENCE_HIGHER_CONSISTENCY

response, err := client.streamedListObjects(ctx).
response, err := client.StreamedListObjects(ctx).
Body(ClientStreamedListObjectsRequest{
Type: "document",
Relation: "viewer",
Expand Down Expand Up @@ -162,7 +162,7 @@ func TestClientStreamedListObjects_ErrorHandling(t *testing.T) {

ctx := context.Background()

_, err = client.streamedListObjects(ctx).
_, err = client.StreamedListObjects(ctx).
Body(ClientStreamedListObjectsRequest{
Type: "document",
Relation: "viewer",
Expand All @@ -187,7 +187,7 @@ func TestClientStreamedListObjects_NoStoreId(t *testing.T) {

ctx := context.Background()

_, err = client.streamedListObjects(ctx).
_, err = client.StreamedListObjects(ctx).
Body(ClientStreamedListObjectsRequest{
Type: "document",
Relation: "viewer",
Expand Down Expand Up @@ -230,7 +230,7 @@ func TestClientStreamedListObjects_CustomBufferSize(t *testing.T) {
ctx := context.Background()
customBufferSize := 50

response, err := client.streamedListObjects(ctx).
response, err := client.StreamedListObjects(ctx).
Body(ClientStreamedListObjectsRequest{
Type: "document",
Relation: "viewer",
Expand Down Expand Up @@ -297,7 +297,7 @@ func TestClientStreamedListObjects_DefaultBufferSize(t *testing.T) {
ctx := context.Background()
zeroBufferSize := 0

response, err := client.streamedListObjects(ctx).
response, err := client.StreamedListObjects(ctx).
Body(ClientStreamedListObjectsRequest{
Type: "document",
Relation: "viewer",
Expand Down
11 changes: 0 additions & 11 deletions example/streamed_list_objects/main.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
// NOTE: This example is currently commented out because streamedListObjects is not publicly accessible
// in the client layer. It may be made public in a future release.

package main

func main() {
// Example temporarily disabled - streamedListObjects is not publicly accessible
}

/*
// Original example code (commented out):

import (
"context"
"encoding/json"
Expand Down Expand Up @@ -209,4 +199,3 @@ func handleError(err error) {
}
os.Exit(1)
}
*/
Loading