chore: version documentation for local and graphql apis
This commit is contained in:
@@ -24,6 +24,7 @@ It's often best practice to write your Collections in separate files and then im
|
|||||||
| **`auth`** | Specify options if you would like this Collection to feature authentication. For more, consult the [Authentication](/docs/authentication/config) documentation. |
|
| **`auth`** | Specify options if you would like this Collection to feature authentication. For more, consult the [Authentication](/docs/authentication/config) documentation. |
|
||||||
| **`upload`** | Specify options if you would like this Collection to support file uploads. For more, consult the [Uploads](/docs/upload/overview) documentation. |
|
| **`upload`** | Specify options if you would like this Collection to support file uploads. For more, consult the [Uploads](/docs/upload/overview) documentation. |
|
||||||
| **`timestamps`** | Set to false to disable documents' automatically generated `createdAt` and `updatedAt` timestamps. |
|
| **`timestamps`** | Set to false to disable documents' automatically generated `createdAt` and `updatedAt` timestamps. |
|
||||||
|
| **`versions`** | Set to true to enable default options, or configure with object properties. [More](/docs/versions/overview#collection-config)|
|
||||||
|
|
||||||
*\* An asterisk denotes that a property is required.*
|
*\* An asterisk denotes that a property is required.*
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ As with Collection configs, it's often best practice to write your Globals in se
|
|||||||
| **`admin`** | Admin-specific configuration. See below for [more detail](/docs/configuration/globals#admin-options). |
|
| **`admin`** | Admin-specific configuration. See below for [more detail](/docs/configuration/globals#admin-options). |
|
||||||
| **`hooks`** | Entry points to "tie in" to collection actions at specific points. [More](/docs/hooks/overview#global-hooks) |
|
| **`hooks`** | Entry points to "tie in" to collection actions at specific points. [More](/docs/hooks/overview#global-hooks) |
|
||||||
| **`access`** | Provide access control functions to define exactly who should be able to do what with this Global. [More](/docs/access-control/overview/#globals) |
|
| **`access`** | Provide access control functions to define exactly who should be able to do what with this Global. [More](/docs/access-control/overview/#globals) |
|
||||||
|
| **`versions`** | Set to true to enable default options, or configure with object properties. [More](/docs/versions/overview#globals-config)|
|
||||||
|
|
||||||
*\* An asterisk denotes that a property is required.*
|
*\* An asterisk denotes that a property is required.*
|
||||||
|
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ const result = await payload.find({
|
|||||||
depth: 2,
|
depth: 2,
|
||||||
page: 1,
|
page: 1,
|
||||||
limit: 10,
|
limit: 10,
|
||||||
where: {} // pass a `where` query here
|
where: {}, // pass a `where` query here
|
||||||
sort: '-title',
|
sort: '-title',
|
||||||
locale: 'en',
|
locale: 'en',
|
||||||
fallbackLocale: false,
|
fallbackLocale: false,
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ Global versions are stored the same as the collection version shown above, excep
|
|||||||
|
|
||||||
Versions expose new operations for both collections and globals. They allow you to find and query versions, find a single version by ID, and publish (or restore) a version by ID. Both Collections and Globals support the same new operations. They are used primarily by the admin UI, but if you are writing custom logic in your app and would like to utilize them, they're available for you to use as well via REST, GraphQL, and Local APIs.
|
Versions expose new operations for both collections and globals. They allow you to find and query versions, find a single version by ID, and publish (or restore) a version by ID. Both Collections and Globals support the same new operations. They are used primarily by the admin UI, but if you are writing custom logic in your app and would like to utilize them, they're available for you to use as well via REST, GraphQL, and Local APIs.
|
||||||
|
|
||||||
**New collection REST endpoints:**
|
**Collection REST endpoints:**
|
||||||
|
|
||||||
| Method | Path | Description |
|
| Method | Path | Description |
|
||||||
| -------- | ------------------------------------ | -------------------------------------- |
|
| -------- | ------------------------------------ | -------------------------------------- |
|
||||||
@@ -105,15 +105,72 @@ Versions expose new operations for both collections and globals. They allow you
|
|||||||
| `GET` | `/api/{collectionSlug}/versions/:id` | Find a specific version by ID |
|
| `GET` | `/api/{collectionSlug}/versions/:id` | Find a specific version by ID |
|
||||||
| `POST` | `/api/{collectionSlug}/versions/:id` | Restore a version by ID |
|
| `POST` | `/api/{collectionSlug}/versions/:id` | Restore a version by ID |
|
||||||
|
|
||||||
**New collection GraphQL queries and mutations:**
|
**Collection GraphQL queries:**
|
||||||
|
|
||||||
TODO: add GraphQL docs here
|
| Query Name | Operation |
|
||||||
|
| ---------------------- | -------------|
|
||||||
|
| **`version{collection.label.singular}`** | `findVersionByID` |
|
||||||
|
| **`versions{collection.label.plural}`** | `findVersions` |
|
||||||
|
|
||||||
**New collection Local API methods:**
|
**And mutation:**
|
||||||
|
|
||||||
TODO: add Local API docs here
|
| Query Name | Operation |
|
||||||
|
| ---------------------- | -------------|
|
||||||
|
| **`restoreVersion{collection.label.singular}`** | `restoreVersion` |
|
||||||
|
|
||||||
**New global REST endpoints:**
|
**Collection Local API methods:**
|
||||||
|
|
||||||
|
#### Find
|
||||||
|
|
||||||
|
```js
|
||||||
|
// Result will be a paginated set of Versions.
|
||||||
|
// See /docs/queries/pagination for more.
|
||||||
|
const result = await payload.findVersions({
|
||||||
|
collection: 'posts', // required
|
||||||
|
depth: 2,
|
||||||
|
page: 1,
|
||||||
|
limit: 10,
|
||||||
|
where: {}, // pass a `where` query here
|
||||||
|
sort: '-createdAt',
|
||||||
|
locale: 'en',
|
||||||
|
fallbackLocale: false,
|
||||||
|
user: dummyUser,
|
||||||
|
overrideAccess: false,
|
||||||
|
showHiddenFields: true,
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Find by ID
|
||||||
|
|
||||||
|
```js
|
||||||
|
// Result will be a Post document.
|
||||||
|
const result = await payload.findVersionByID({
|
||||||
|
collection: 'posts', // required
|
||||||
|
id: '507f1f77bcf86cd799439013', // required
|
||||||
|
depth: 2,
|
||||||
|
locale: 'en',
|
||||||
|
fallbackLocale: false,
|
||||||
|
user: dummyUser,
|
||||||
|
overrideAccess: false,
|
||||||
|
showHiddenFields: true,
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Restore
|
||||||
|
|
||||||
|
```js
|
||||||
|
// Result will be the restored global document.
|
||||||
|
const result = await payload.restoreVersion({
|
||||||
|
collection: 'posts', // required
|
||||||
|
id: '507f1f77bcf86cd799439013', // required
|
||||||
|
depth: 2,
|
||||||
|
user: dummyUser,
|
||||||
|
overrideAccess: false,
|
||||||
|
showHiddenFields: true,
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
**Global REST endpoints:**
|
||||||
|
|
||||||
| Method | Path | Description |
|
| Method | Path | Description |
|
||||||
| -------- | ---------------------------------------- | -------------------------------------- |
|
| -------- | ---------------------------------------- | -------------------------------------- |
|
||||||
@@ -121,13 +178,70 @@ TODO: add Local API docs here
|
|||||||
| `GET` | `/api/globals/{globalSlug}/versions/:id` | Find a specific version by ID |
|
| `GET` | `/api/globals/{globalSlug}/versions/:id` | Find a specific version by ID |
|
||||||
| `POST` | `/api/globals/{globalSlug}/versions/:id` | Restore a version by ID |
|
| `POST` | `/api/globals/{globalSlug}/versions/:id` | Restore a version by ID |
|
||||||
|
|
||||||
**New global GraphQL queries and mutations:**
|
**Global GraphQL queries:**
|
||||||
|
|
||||||
TODO: add GraphQL docs here
|
| Query Name | Operation |
|
||||||
|
| ---------------------- | -------------|
|
||||||
|
| **`version{global.label}`** | `findVersionByID` |
|
||||||
|
| **`versions{global.label}`** | `findVersions` |
|
||||||
|
|
||||||
**New global Local API methods:**
|
**Global GraphQL mutation:**
|
||||||
|
|
||||||
TODO: add Local API docs here
|
| Query Name | Operation |
|
||||||
|
| ---------------------- | -------------|
|
||||||
|
| **`restoreVersion{global.label}`** | `restoreVersion` |
|
||||||
|
|
||||||
|
**Global Local API methods:**
|
||||||
|
|
||||||
|
#### Find
|
||||||
|
|
||||||
|
```js
|
||||||
|
// Result will be a paginated set of Versions.
|
||||||
|
// See /docs/queries/pagination for more.
|
||||||
|
const result = await payload.findGlobalVersions({
|
||||||
|
slug: 'header', // required
|
||||||
|
depth: 2,
|
||||||
|
page: 1,
|
||||||
|
limit: 10,
|
||||||
|
where: {}, // pass a `where` query here
|
||||||
|
sort: '-createdAt',
|
||||||
|
locale: 'en',
|
||||||
|
fallbackLocale: false,
|
||||||
|
user: dummyUser,
|
||||||
|
overrideAccess: false,
|
||||||
|
showHiddenFields: true,
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Find by ID
|
||||||
|
|
||||||
|
```js
|
||||||
|
// Result will be a Post document.
|
||||||
|
const result = await payload.findGlobalVersionByID({
|
||||||
|
slug: 'header', // required
|
||||||
|
id: '507f1f77bcf86cd799439013', // required
|
||||||
|
depth: 2,
|
||||||
|
locale: 'en',
|
||||||
|
fallbackLocale: false,
|
||||||
|
user: dummyUser,
|
||||||
|
overrideAccess: false,
|
||||||
|
showHiddenFields: true,
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Restore
|
||||||
|
|
||||||
|
```js
|
||||||
|
// Result will be the restored global document.
|
||||||
|
const result = await payload.restoreGlobalVersion({
|
||||||
|
slug: 'header', // required
|
||||||
|
id: '507f1f77bcf86cd799439013', // required
|
||||||
|
depth: 2,
|
||||||
|
user: dummyUser,
|
||||||
|
overrideAccess: false,
|
||||||
|
showHiddenFields: true,
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
### Access Control
|
### Access Control
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,13 @@
|
|||||||
import findOne from './findOne';
|
import findOne from './findOne';
|
||||||
import update from './update';
|
import update from './update';
|
||||||
|
import findVersionByID from './findVersionByID';
|
||||||
|
import findVersions from './findVersions';
|
||||||
|
import restoreVersion from './restoreVersion';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
findOne,
|
findOne,
|
||||||
update,
|
update,
|
||||||
|
findVersionByID,
|
||||||
|
findVersions,
|
||||||
|
restoreVersion,
|
||||||
};
|
};
|
||||||
|
|||||||
36
src/index.ts
36
src/index.ts
@@ -49,6 +49,9 @@ import { Options as DeleteOptions } from './collections/operations/local/delete'
|
|||||||
import { Options as FindVersionsOptions } from './collections/operations/local/findVersions';
|
import { Options as FindVersionsOptions } from './collections/operations/local/findVersions';
|
||||||
import { Options as FindVersionByIDOptions } from './collections/operations/local/findVersionByID';
|
import { Options as FindVersionByIDOptions } from './collections/operations/local/findVersionByID';
|
||||||
import { Options as RestoreVersionOptions } from './collections/operations/local/restoreVersion';
|
import { Options as RestoreVersionOptions } from './collections/operations/local/restoreVersion';
|
||||||
|
import { Options as FindGlobalVersionsOptions } from './globals/operations/local/findVersions';
|
||||||
|
import { Options as FindGlobalVersionByIDOptions } from './globals/operations/local/findVersionByID';
|
||||||
|
import { Options as RestoreGlobalVersionOptions } from './globals/operations/local/restoreVersion';
|
||||||
import { Result } from './auth/operations/login';
|
import { Result } from './auth/operations/login';
|
||||||
|
|
||||||
require('isomorphic-fetch');
|
require('isomorphic-fetch');
|
||||||
@@ -246,6 +249,39 @@ export class Payload {
|
|||||||
return update(options);
|
return update(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Find global versions with criteria
|
||||||
|
* @param options
|
||||||
|
* @returns versions satisfying query
|
||||||
|
*/
|
||||||
|
findGlobalVersions = async <T extends TypeWithVersion<T> = any>(options: FindGlobalVersionsOptions): Promise<PaginatedDocs<T>> => {
|
||||||
|
let { findVersions } = localGlobalOperations;
|
||||||
|
findVersions = findVersions.bind(this);
|
||||||
|
return findVersions<T>(options);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Find global version by ID
|
||||||
|
* @param options
|
||||||
|
* @returns global version with specified ID
|
||||||
|
*/
|
||||||
|
findGlobalVersionByID = async <T extends TypeWithVersion<T> = any>(options: FindGlobalVersionByIDOptions): Promise<T> => {
|
||||||
|
let { findVersionByID } = localGlobalOperations;
|
||||||
|
findVersionByID = findVersionByID.bind(this);
|
||||||
|
return findVersionByID(options);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Restore global version by ID
|
||||||
|
* @param options
|
||||||
|
* @returns version with specified ID
|
||||||
|
*/
|
||||||
|
restoreGlobalVersion = async <T extends TypeWithVersion<T> = any>(options: RestoreGlobalVersionOptions): Promise<T> => {
|
||||||
|
let { restoreVersion } = localGlobalOperations;
|
||||||
|
restoreVersion = restoreVersion.bind(this);
|
||||||
|
return restoreVersion(options);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description Find document by ID
|
* @description Find document by ID
|
||||||
* @param options
|
* @param options
|
||||||
|
|||||||
Reference in New Issue
Block a user