openfga / api

Protocol Buffers used by OpenFGA
Apache License 2.0
19 stars 14 forks source link

Write API: make TupleKeys more canonical #79

Open jon-whit opened 1 year ago

jon-whit commented 1 year ago

Today the Write API looks like:

message WriteRequest {
    string store_id = 1;
    TupleKeys writes = 2;
    TupleKeys deletes = 3;
    string authorization_model_id = 4;
}

message TupleKeys {
    repeated TupleKey tuple_keys = 1;
}

message TupleKey {
    string object = 1;
    string relation = 2;
    string user = 3;
}

The usage of TupleKeys is completely unnecessary and makes the API and related code stutter. For example in Go code we have:

tupleKeys := openfgapb.TupleKeys{
    TupleKeys: []*openfgapb.TupleKey{...}
}

I propose we make this more canonical with simply:

message WriteRequest {
    string store_id = 1;
    repeated TupleKey writes = 2;
    repeated TupleKey deletes = 3;
    string authorization_model_id = 4;
}

and the corresponding code in Go will simply look like:

tupleKeys := []*openfgapb.TupleKey{...}

Note that these changes are a breaking change to the API though. The HTTP request body and gRPC request bodies change in an incompatible way.

{
    "writes": {
        "tuple_keys": [...]
    },
    "deletes": {
        "tuple_keys": [...]
    }
}

becomes

{
    "writes": [...],
    "deletes": [...]
}