Cleanup union type docs

This commit is contained in:
rijkvanzanten
2021-04-23 10:41:59 -04:00
parent 1000988c32
commit 775ceaccc4
2 changed files with 68 additions and 26 deletions

View File

@@ -78,7 +78,7 @@ nullifying the field:
}
```
#### One-to-Many (/ Many-to-Many / Many-to-Any)
#### One-to-Many (/ Many-to-Many)
One-to-Many, and therefore Many-to-Many and Many-to-Any, relationships can be updated in one of two ways:
@@ -145,3 +145,70 @@ foreign key. This means that your data will never suddenly disappear, but it als
orphaned items.
:::
#### Many-to-Any (Union Types)
Many-to-Any fields work very similar to a "regular" many-to-many, with the exception that the related field can pull in
the fields from any of the related collections, for example:
```json
{
"sections": [
{
"collection": "headings",
"item": {
/* headings fields */
}
},
{
"collection": "paragraphs",
"item": {
/* paragraphs fields */
}
}
]
}
```
##### REST API
To scope the fields that are returned per collection type, you can use the `<field>:<scope>` syntax in the fields
parameter as follows:
```
GET /items/pages
?fields[]=sections.item:headings.id
&fields[]=sections.item:headings.title
&fields[]=sections.item:paragraphs.body
&fields[]=sections.item:paragraphs.background_color
```
##### GraphQL
In GraphQL, you can use nested fragments on the Union Type to select the fields:
```graphql
query {
pages {
sections {
item {
... on headings {
id
title
}
... on paragraphs {
body
background_color
}
}
}
}
}
```
::: tip Updating
Updating records in a many-to-any is identical to the other relationship types.
:::

View File

@@ -74,10 +74,6 @@ will be an empty array.
If your collection is a singleton, this endpoint will return the item.
#### Example for M2M relation
Let's imagine each article can be related to one or multiple `themes`.
</div>
<div class="right">
@@ -115,27 +111,6 @@ query {
}
```
##### Example with themes related to an article with a M2M relation
```graphql
query {
articles {
id
title
author {
first_name
}
themes {
item {
... on them {
label
}
}
}
}
}
```
</div>
</div>