File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -140,6 +140,43 @@ const results = await promiseClient.readRelationships(/** req **/);
140140console .log (results[0 ]); // first ReadRelationship result
141141```
142142
143+ ## Writing Caveats
144+
145+ When writing caveat context to a relation, we've observed that you need to use
146+ the ` Struct ` object bundled with ` authzed-node ` , rather than importing it from
147+ the ` google-protobuf ` package. If you don't use the ` authzed-node ` version,
148+ writing context will fail silently and the relations won't reflect the context.
149+
150+ An example:
151+
152+ ``` js
153+ import { protobuf } from ' @authzed/authzed-node' ;
154+ const { Struct } = protobuf;
155+
156+ const writeRequest = WriteRelationshipsRequest .create ({
157+ updates: [
158+ RelationshipUpdate .create ({
159+ relationship: Relationship .create ({
160+ resource: resource,
161+ relation: " caveated_viewer" ,
162+ subject: SubjectReference .create ({
163+ object: testUser,
164+ }),
165+ optionalCaveat: ContextualizedCaveat .create ({
166+ caveatName: " has_special_attribute" ,
167+ context: Struct .fromJson ({
168+ special: true ,
169+ }),
170+ }),
171+ }),
172+ operation: RelationshipUpdate_Operation .CREATE ,
173+ }),
174+ ],
175+ });
176+
177+ const response = await client .writeRelationships (writeRequest);
178+ ```
179+
143180## Requirements
144181
145182Supported Node.js versions: 18, 20, 22
You can’t perform that action at this time.
0 commit comments