method

BoundTypedCollection.SaveDraft

Stage incomplete edits without replacing a document's published snapshot.

Example

go
pages := generated.PagesCollection.With(app.Local())
saved, err := pages.SaveDraft(
  ctx, draft.ID,
  generated.PageDraft{Title: core.Null[string]()},
  core.TypedMutationOptions{
    Actor: &session.User,
    ActorCollection: session.Collection,
    ExpectedRevision: draft.Revision,
  },
)
if err != nil {
  return err
}
_ = saved.Revision

Arguments

ArgumentTypeDescription
ctxcontext.ContextCancellation context for the access-controlled update transaction.
idstringThe document to update.
inputDraftThe generated draft patch. Nil fields retain saved values; core.Null clears an editorial field. Keyed rows preserve their occurrence identities.
optionsTypedMutationOptionsCaller identity, locale and ExpectedRevision from the last working read. Draft is forced to true.

Returns

The saved working document with a new revision, or an operation error such as conflict for a stale ExpectedRevision.

(Document, error)

How it works

Saved pending values remain separate from live content. Publish validates the complete working candidate before replacing the live snapshot; DiscardDraft resets the working head to that live snapshot.

Full signature

func (collection BoundTypedCollection[Document, Create, Update, Draft]) SaveDraft( ctx context.Context, id string, input Draft, options TypedMutationOptions, ) (Document, error)

Source core/typed_local.go:106

Related types

  • BoundTypedCollection

    Typed collection methods for strict writes, incomplete working drafts, publication, reads, and deletion.

  • TypedMutationOptions

    Actor, draft intent, expected revision, locale, and response controls for a generated Go mutation.

Related guides