feat: adds maxDepth to relationships and upload fields

This commit is contained in:
Dan Ribbens
2021-06-22 13:28:27 -04:00
parent c2e6aae545
commit 880dabdcad
7 changed files with 15 additions and 2 deletions

View File

@@ -240,6 +240,13 @@ const AllFields: PayloadCollectionConfig = {
name: 'relationshipMultipleCollections',
relationTo: ['localized-posts', 'conditions'],
},
{
type: 'relationship',
label: 'Relationship with maxDepth',
name: 'relationshipMaxDepth',
relationTo: 'relationship-a',
maxDepth: 1,
},
{
type: 'textarea',
label: 'Textarea',

View File

@@ -23,6 +23,7 @@ keywords: relationship, fields, config, configuration, documentation, Content Ma
| **`name`** * | To be used as the property name when stored and retrieved from the database. |
| **`*relationTo`** * | Provide one or many collection `slug`s to be able to assign relationships to. |
| **`hasMany`** | Boolean when, if set to `true`, allows this field to have many relations instead of only one. |
| **`maxDepth`** | Sets a number limit on iterations of related documents to populate when queried. |
| **`label`** | Used as a field label in the Admin panel and to name the generated GraphQL type. |
| **`unique`** | Enforce that each entry in the Collection has a unique value for this field. |
| **`validate`** | Provide a custom validation function that will be executed on both the Admin panel and the backend. [More](/docs/fields/overview#validation) |

View File

@@ -27,6 +27,7 @@ keywords: upload, images media, fields, config, configuration, documentation, Co
| ---------------- | ----------- |
| **`name`** * | To be used as the property name when stored and retrieved from the database. |
| **`*relationTo`** * | Provide a single collection `slug` to allow this field to accept a relation to. <strong>Note: the related collection must be configured to support Uploads.</strong> |
| **`maxDepth`** | Sets a number limit on iterations of related documents to populate when queried. |
| **`label`** | Used as a field label in the Admin panel and to name the generated GraphQL type. |
| **`unique`** | Enforce that each entry in the Collection has a unique value for this field. |
| **`validate`** | Provide a custom validation function that will be executed on both the Admin panel and the backend. [More](/docs/fields/overview#validation) |

View File

@@ -69,7 +69,7 @@ For more, visit the [Access Control documentation](/docs/access-control/overview
</Banner>
You can specify population `depth` via query parameter in the REST API and by an option in the local API. *Depth has no effect in the GraphQL API, because there, depth is based on the shape of your queries.*
It is also possible to limit the depth for a specific field using the `maxDepth` property in your configuration.
**For example, let's look the following Collections:** `departments`, `users`, `posts`
```

View File

@@ -60,7 +60,7 @@ const accessPromise = async ({
relationshipPopulations.push(relationshipPopulationPromise({
data,
field,
depth,
depth: field.maxDepth || depth,
currentDepth,
req,
overrideAccess,

View File

@@ -171,6 +171,7 @@ export const upload = baseField.keys({
type: joi.string().valid('upload').required(),
relationTo: joi.string().required(),
name: joi.string().required(),
maxDepth: joi.number(),
});
export const checkbox = baseField.keys({
@@ -187,6 +188,7 @@ export const relationship = baseField.keys({
joi.array().items(joi.string()),
),
name: joi.string().required(),
maxDepth: joi.number(),
});
export const blocks = baseField.keys({

View File

@@ -141,6 +141,7 @@ export type RowField = FieldBase & {
export type UploadField = FieldBase & {
type: 'upload';
relationTo: string;
maxDepth?: number;
}
type CodeAdmin = Admin & {
@@ -164,6 +165,7 @@ export type RelationshipField = FieldBase & {
type: 'relationship';
relationTo: string | string[];
hasMany?: boolean;
maxDepth?: number;
}
type RichTextPlugin = (editor: Editor) => Editor;