Typescript in SpiceDB
# spicedb
l
Hello, I am trying to add relationships to my spicedb but i am having trouble getting it to work with typescript. I was wondering what others have done (or if I should just do it in js). Thank you in advance
y
what's the specific problem you're running into?
l
@Joey thank you! the examples helped and I got it fixed
I was getting
Copy code
Error: Incorrect arguments passed
because I was formatting the request wrong
Also, I was looking at the docs (https://buf.build/authzed/api/docs/main:authzed.api.v1#authzed.api.v1.PermissionsService.WriteRelationships) and it stated that WriteRelationship can write, delete (and update?) relationships. I looked at the code you shared with me and I was able to add relationships; however, I am a bit confused with deleting or updating. do I change
Copy code
operation: RelationshipUpdate_Operation.CREATE
to
Copy code
operation: RelationshipUpdate_Operation.TOUCH
or
Copy code
operation: RelationshipUpdate_Operation.DELETE
do I need to provide extra info?
y
you use
WriteRelationships
when you need to create or delete a specific relation
CREATE
and
TOUCH
will both create a relationship;
CREATE
errors if it already exists
DELETE
removes a relationship or noops if the relation doesn't exist
l
ah ok, and if I want to update a relationship (promote someone from reader to writer) should i delete the old relationship and create a new one, or is that what the TOUCH is for?
j
you delete the old one and create a new one
it is a different relationship
l
awesome thanks!
48 Views