-
Notifications
You must be signed in to change notification settings - Fork 19
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
Add examples for reading relationships in the node client #79
Comments
@MadaPas A good source of reference might be here: GitPod seems to have a pretty decent Spice client implementation written in TS. |
Hi! |
Hi @MadaPas! Gitpod has been using SpiceDB for a while now, so their client is definitely more developed and harder to learn from.
The team has discussed improving the documentation for the different clients, especially the TypeScript client since it is one of the most widely used. What kind of examples would be most valuable to you? We could start with just adding usage examples for each method.
For this error specifically, could you include a small code snippet? I suspect this is something very simple. P.S. The SpiceDB team and community is very active on Discord too and can help walk you though other issues you might be having. |
@MadaPas Are you still having trouble with the ReadRelationships API? |
Hi @alecmerdler !
Currently I am a bit stuck when I try to delete certain relationships. Some code for context:
I get the following error at
My take on it is that I am not using |
Hi! |
@MadaPas You can find the type signature for the If you can, I highly recommend using TypeScript with this client as it makes it much more obvious what parameters and return types that the client uses. Even if your project isn't using TypeScript, many text editors (like VSCode) should still allow you to jump into the method definitions to validate that you are passing the right arguments. |
We're diving into SpiceDb and currently focused on syncing relationships from various data sources. Our approach involves an initial "full sync" from relevant databases, creating relationships. Subsequently, we aim to perform continuous updates by handling single new relationships as they occur in our databases. However, we're encountering a challenge during the full sync, where fetching data from an API and creating relationships works fine initially. Still, on subsequent triggers, it fails due to attempting to create an already existing relationship.
One quick, short-term solution to this was to use
RelationshipUpdate_Operation.TOUCH
instead ofCREATE
, but on the long run, we would like to be able to read existing relationships, so on subsequent triggers, we can control creating new relationships, as well as deleting the ones that are out of sync.To address this, we've devised a strategy to fetch all existing relationships of a specific type and then appropriately skip existing ones, delete, or create single relationships.
We are currently getting stuck at just reading all the existing relationships of a type…
Here's an overview:
We've defined two entities in our schema -
team
andemployee
. The team has amember
relation withemployee
. Our goal is to read relationships for a specific resource, where the relation ismember
, essentially fetching all employees that are members of a particular team.We've crafted a function utilizing the SpiceDb API to read relationships. The function, responsible for reading existing relationships, follows these steps:
ObjectReference
for the entity using thev1.ObjectReference.create
method.ReadRelationshipsRequest
specifying details about the relationship to be read. It includes theObjectReference
and sets the relation tomember
gRPC
: Invokingclient.readRelationships
method with the definedreadRelationshipsRequest
.Currently, we get the error: "Cannot read properties of undefined (reading 'create')."
Would be useful to have some documentation available on the correct procedure for this, to be able to assess where I might be going wrong.
The text was updated successfully, but these errors were encountered: