@@ -601,14 +601,122 @@ var response = fgaClient.check(request, options).get();
601601
602602##### Batch Check
603603
604- Run a set of [ checks] ( #check ) . Batch Check will return ` allowed: false ` if it encounters an error, and will return the error in the body.
605- If 429s or 5xxs are encountered, the underlying check will retry up to 3 times before giving up.
604+ Similar to [ check] ( #check ) , but instead of checking a single user-object relationship, accepts a list of relationships to check. Requires OpenFGA version 1.8.0 or greater.
605+
606+ [ API Documentation] ( https://openfga.dev/api/service#/Relationship%20Queries/BatchCheck )
606607
607- > Passing ` ClientBatchCheckClientOptions ` is optional. All fields of ` ClientBatchCheckClientOptions ` are optional.
608+ > Passing ` ClientBatchCheckOptions ` is optional. All fields of ` ClientBatchCheckOptions ` are optional.
608609
609610``` java
611+ var reequst = new ClientBatchCheckRequest (). checks(
612+ List . of(
613+ new ClientBatchCheckItem ()
614+ .user(" user:81684243-9356-4421-8fbf-a4f8d36aa31b" )
615+ .relation(" viewer" )
616+ ._object(" document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a" )
617+ .correlationId(" cor-1" ) // optional, one will be generated for you if not provided
618+ .contextualTuples(List . of(
619+ new ClientTupleKey ()
620+ .user(" user:81684243-9356-4421-8fbf-a4f8d36aa31b" )
621+ .relation(" editor" )
622+ ._object(" document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a" )
623+ )),
624+ new ClientCheckRequest ()
625+ .user(" user:81684243-9356-4421-8fbf-a4f8d36aa31b" )
626+ .relation(" admin" )
627+ ._object(" document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a" ),
628+ .correlationId(" cor-2" ) // optional, one will be generated for you if not provided
629+ .contextualTuples(List . of(
630+ new ClientTupleKey ()
631+ .user(" user:81684243-9356-4421-8fbf-a4f8d36aa31b" )
632+ .relation(" editor" )
633+ ._object(" document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a" )
634+ )),
635+ new ClientCheckRequest ()
636+ .user(" user:81684243-9356-4421-8fbf-a4f8d36aa31b" )
637+ .relation(" creator" )
638+ ._object(" document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a" )
639+ .correlationId(" cor-3), // optional, one will be generated for you if not provided
640+ new ClientCheckRequest()
641+ .user(" user: 81684243 - 9356 - 4421 - 8fbf- a4f8d36aa31b" )
642+ .relation(" deleter" )
643+ ._object(" document: 0192ab2a- d83f- 756d - 9397 - c5ed9f3cb69a" )
644+ .correlationId(" cor- 4 " ) // optional, one will be generated for you if not provided
645+ )
646+ );
647+
648+ var options = new ClientBatchCheckOptions()
649+ .additionalHeaders(Map.of(" Some - Http - Header " , " Some value" ))
650+ // You can rely on the model id set in the configuration or override it for this specific request
651+ .authorizationModelId(" 01GXSA8YR785C4FYS3C0RTG7B1" )
652+ .maxParallelRequests(5); // Max number of requests to issue in parallel, defaults to 10
653+ .maxBatchSize(20); // Max number of batches to split the list of checks into, defaults to 50
654+
655+ var response = fgaClient.batchCheck(request, options).get();
656+
657+ /*
658+ response.getResult() = [{
659+ allowed: false,
660+ correlationId: " cor- 1 " ,
661+ request: {
662+ user: " user: 81684243 - 9356 - 4421 - 8fbf- a4f8d36aa31b" ,
663+ relation: " viewer" ,
664+ _object: " document: 0192ab2a- d83f- 756d - 9397 - c5ed9f3cb69a" ,
665+ correlationId: " cor- 1 " ,
666+ contextualTuples: [{
667+ user: " user: 81684243 - 9356 - 4421 - 8fbf- a4f8d36aa31b" ,
668+ relation: " editor" ,
669+ _object: " document: 0192ab2a- d83f- 756d - 9397 - c5ed9f3cb69a"
670+ }]
671+ },
672+ },
673+ {
674+ allowed: false,
675+ correlationId: " cor- 2 " ,
676+ request: {
677+ user: " user: 81684243 - 9356 - 4421 - 8fbf- a4f8d36aa31b" ,
678+ relation: " admin" ,
679+ _object: " document: 0192ab2a- d83f- 756d - 9397 - c5ed9f3cb69a" ,
680+ correlationId: " cor- 2 " ,
681+ contextualTuples: [{
682+ user: " user: 81684243 - 9356 - 4421 - 8fbf- a4f8d36aa31b" ,
683+ relation: " editor" ,
684+ _object: " document: 0192ab2a- d83f- 756d - 9397 - c5ed9f3cb69a"
685+ }]
686+ }
687+ },
688+ {
689+ allowed: false,
690+ correlationId: " cor- 3 " ,
691+ request: {
692+ user: " user: 81684243 - 9356 - 4421 - 8fbf- a4f8d36aa31b" ,
693+ relation: " creator" ,
694+ _object: " document: 0192ab2a- d83f- 756d - 9397 - c5ed9f3cb69a" ,
695+ correlationId: " cor- 3 " ,
696+ },
697+ error: <FgaError ...>
698+ },
699+ {
700+ allowed: true,
701+ correlationId: " cor- 4 " ,
702+ request: {
703+ user: " user: 81684243 - 9356 - 4421 - 8fbf- a4f8d36aa31b" ,
704+ relation: " deleter" ,
705+ _object: " document: 0192ab2a- d83f- 756d - 9397 - c5ed9f3cb69a" ,
706+ correlationId: " cor- 4 " ,
707+ }
708+ },
709+ ]
710+ */
711+ ```
712+
713+ If you are using an OpenFGA version less than 1.8.0, you can use `clientBatchCheck`,
714+ which calls `check` in parallel. It will return `allowed: false` if it encounters an error, and will return the error in the body.
715+ If 429s or 5xxs are encountered, the underlying check will retry up to 3 times before giving up.
716+
717+ ```
610718var request = List.of(
611- new ClientCheckRequest ()
719+ new ClientBatchCheckItem ()
612720 .user(" user: 81684243 - 9356 - 4421 - 8fbf- a4f8d36aa31b" )
613721 .relation(" viewer" )
614722 ._object(" document: 0192ab2a- d83f- 756d - 9397 - c5ed9f3cb69a" )
0 commit comments