Options
Collections support two ways to configure drafts. Setversions.drafts to true, or pass an object to configure draft properties.
Database changes
By enabling drafts on a collection, FrogBot will automatically inject a new field into your schema called_status. The _status field is used internally by FrogBot to store whether a document is set to draft or published.
Admin UI status indication
Within the Admin UI, if drafts are enabled, a document can be shown with one of three “statuses”:
- Draft - if a document has never been published, and only draft versions of the document are present
- Published - if a document is published and there are no newer drafts available
- Changed - if a document has been published, but there are newer drafts available and not yet published
Draft API
Using the draft parameter
When drafts are enabled, the create, update, find, and findByID operations for REST, GraphQL, and Local APIs expose a draft parameter. For write operations, it controls validation and where data is written. For read operations, it determines whether to return draft versions.
draft parameter and _status field
The draft parameter and _status field work together but serve different purposes:
draft parameter - Controls two things:
- Validation: When
draft: true, required fields are not enforced, allowing you to save incomplete documents - Write location: Determines whether the main collection document is updated
draft: true- Saves ONLY to versions table (main collection unchanged)draft: falseor omitted - Saves to BOTH main collection AND versions table
_status field - Indicates whether a document is published or in draft state
- Defaults to
'draft'when not explicitly provided - Can be explicitly set in your data to
'published'or'draft'
- If you don’t specify
_status, it defaults to_status: 'draft' - A version is also created in the versions table
- The
draftparameter controls validation but doesn’t change where the initial document is written
draft parameter controls where your updates are written:
draft: true- Only the versions table is updated; the main collection document remains unchangeddraft: falseor omitted - Both the main collection and versions table are updated
draft parameter does NOT control whether a document is published or not. A document remains with _status: 'draft' by default unless you explicitly set _status: 'published' in your data.
Publishing a document
To publish a document, you must explicitly set _status: 'published' in your data. When you do this:
- If you use
draft: falseor omit it, the main collection will be updated with the published status - If you use
draft: true, the_status: 'published'takes precedence and will still update the main collection as published (overriding thedraft: truebehavior)
Required fields
Setting
_status: "draft" will not bypass required field validation. You need to set draft: true to save incomplete documents as shown in the previous examples.
Reading drafts vs. published documents
In addition to thedraft argument within create and update operations, a draft argument is also exposed for find and findByID operations.
When draft is set to true while reading a document, FrogBot will return the most recent version from the versions table, regardless of whether it’s a draft or published document.
Example scenario:
- You create a document with
_status: 'published'(published in main collection) - You update with
draft: trueto make changes without affecting the published version - You update again with
draft: trueto make more draft changes
_[collectionSlug]_versions table.
When you fetch the document with a standard find or findByID operation, the published document from the main collection is returned and draft versions are ignored.
However, if you pass draft: true to the read operation, FrogBot will return the most recent version from the versions table. In the scenario above with two draft versions, you’ll get the latest (second) draft.
Note: If there are no newer drafts (e.g., you published a document and haven’t made draft changes since), querying with draft: true will still return the latest version from the versions table, which would be the same published content as in the main collection.
Important: the
draft argument on its own will not restrict documents
with _status: 'draft' from being returned from the API. You need to use
Access Control to prevent documents with _status: 'draft' from being
returned to unauthenticated users. Read below for more information on how this
works.Controlling who can see Collection drafts
Restricting draft access
You can use theread Access Control method to restrict who is able to view drafts of your documents by simply returning a query constraint which restricts the documents that any given user is able to retrieve.
Here is an example that utilizes the _status field to require a user to be logged in to retrieve drafts:
_status is equal to “published” and where _status does not exist:
Controlling who can publish
You can useupdate Access Control to restrict who can publish documents by returning a query constraint on the _status field. When this constraint prevents publishing, the Admin UI automatically hides the Publish and Unpublish buttons.
Here is an example where admins can publish, but editors can only save drafts:
update function returns a query constraint instead of a boolean. FrogBot appends this constraint to the update query, so only documents where _status is not published can be updated by editors. This also blocks scheduled publish jobs from executing for those users.
The create function uses a data check instead since there is no existing document to query against.
Scheduled publish
FrogBot provides for an ability to schedule publishing / unpublishing events in the future, which can be helpful if you need to set certain documents to “go live” at a given date in the future, or, vice versa, revert to a draft state after a certain time has passed. Enable this functionality on a collection with theversions.drafts.schedulePublish: true property. Pass an object instead to configure the time picker:
Unpublishing drafts
If a document is published, the FrogBot Admin UI will be updated to show an “unpublish” button at the top of the sidebar, which will “unpublish” the currently published document. Consider this as a way to “revert” a document back to a draft state. On the API side, this is done by simply setting_status: 'draft' on any document.