Skip to content

Commit 4032ddf

Browse files
committed
Convert context into query string for FGA queries
1 parent 3e9d91e commit 4032ddf

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

tests/test_fga.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,3 +534,14 @@ def test_query(self, mock_query_response, mock_http_client_with_response):
534534
warrant_token="warrant_token",
535535
)
536536
assert response.dict(exclude_none=True) == mock_query_response
537+
538+
def test_query_with_context(self, mock_query_response, mock_http_client_with_response):
539+
mock_http_client_with_response(self.http_client, mock_query_response, 200)
540+
541+
response = self.fga.query(
542+
q="select member of type user for permission:view-docs",
543+
order="asc",
544+
warrant_token="warrant_token",
545+
context={"region": "us", "subscription": "pro"},
546+
)
547+
assert response.dict(exclude_none=True) == mock_query_response

workos/fga.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import json
12
from typing import Any, Mapping, Optional, Protocol, Sequence
23
from workos.types.fga import (
34
CheckOperation,
@@ -621,11 +622,16 @@ def query(
621622
"after": after,
622623
"context": context,
623624
}
625+
parsed_list_params = {
626+
key: json.dumps(value) if key == "context" and value is not None else value
627+
for key, value in list_params.items()
628+
if value is not None
629+
}
624630

625631
response = self._http_client.request(
626632
"fga/v1/query",
627633
method=REQUEST_METHOD_GET,
628-
params=list_params,
634+
params=parsed_list_params,
629635
headers={"Warrant-Token": warrant_token} if warrant_token else None,
630636
)
631637

0 commit comments

Comments
 (0)