Skip to content
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

Expose mutationID on WriteTransaction #1027

Open
aboodman opened this issue Oct 12, 2022 · 4 comments
Open

Expose mutationID on WriteTransaction #1027

aboodman opened this issue Oct 12, 2022 · 4 comments
Labels
Fixit Small fix that should go in next release given time

Comments

@aboodman
Copy link
Contributor

It comes up from time to time that it's useful to have a value that is stable across client and server invocations of a mutation. Exposing mutationID would be an easy way to do this.

@BrianHung
Copy link

One use case of this is as a source of entropy unique per mutation that, along with a hashing function, could create deterministic / pseudorandom ids. For example,

import { v5 as hash } from 'uuid';

async function mutator(tx, args) {
  // Creates 10 uuids that are stable per mutation when played on client and server.
  let uuids = Array.from({length: 10}, (_, i) => hash(i, tx.mutationId));
}

@phritz
Copy link
Contributor

phritz commented Oct 12, 2022

The downside is that it exposes a detail of our protocol that people might start to rely on (that it is sequential, that there are no gaps, that it doesn't reset, etc), which constrains what we do with it in the future. ISTM that if what's required is a value that's stable across client and server, the app can simply pick something and pass it in mutator args, be it a counter or random int or guid.

@arv
Copy link
Contributor

arv commented Oct 20, 2022

@phritz I'm not sure exposing this is a big deal. It is part of the protocol that a server needs to implement.

@arv arv added the Fixit Small fix that should go in next release given time label Oct 20, 2022
@aboodman
Copy link
Contributor Author

Yeah I think it would already be a huge change if the semantics of mutationIDs were to change. Every server would already have to change. The JS API change is small by comparison.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fixit Small fix that should go in next release given time
Projects
None yet
Development

No branches or pull requests

4 participants