Given the following schema:
# spicedb
c
Given the following schema:
Copy code
definition token {}
 
definition service {
    relation token: token
}
 
definition resource {
    relation viewer: service#token
}
Is there a way for me to return all
tokens
in SpiceDB?
Looks like I can do something like this:
Copy code
python
res = client.ReadRelationships(
    spice_db.ReadRelationshipsRequest(
        relationship_filter=spice_db.RelationshipFilter(
            resource_type="service",
            optional_subject_filter=spice_db.SubjectFilter(
                subject_type="token"
            )
        )
    )
)
This returns a response where I can do:
Copy code
python
relationship = await res.read()
Is there a way for me to "exhaust" the stream without calling
client.ReadRelationships
again with the cursor-token?
Aah - I see now that I can just continue calling
res.read()
and check for
EOF
or
res.done() is True
y
not sure if it's helpful for your current mental model, but one thing that took me a while to wrap my head around is that spicedb only stores edges, so the notion of "what entities does it store" doesn't really compute
v
ReadRelationships is the way to go here, yeah. And yeah the stream will finish when EOF is returned, which means there are no more relationships to read. You can use the cursor to resume if the process stopped at some point
c
thx 🙂