You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -1660,117 +1660,117 @@ While mutations are mostly straightforward, there are a few important cases to c
1660
1660
1661
1661
### Matrix Fields in Mutations
1662
1662
1663
-
GraphQL’s limited input types can be challenging with complex [Matrix fields](../reference/field-types/matrix.md).
1663
+
Connecting GraphQL’s input types to complex [Matrix fields](../reference/field-types/matrix.md) can be challenging.
1664
1664
1665
1665
::: tip
1666
-
We recommend reading [how to save matrix field data in entry forms](../reference/field-types/matrix.md#saving-matrix-fields-in-entry-forms) first if you’ve not saved Matrix field form data.
1666
+
We recommend studying how to [save Matrix field data in entry forms](../reference/field-types/matrix.md#saving-matrix-fields) before diving in to the equivalent GraphQL.
1667
1667
:::
1668
1668
1669
-
Matrix input types generally have the following structure:
1669
+
Matrix input types have the following structure, and are always named `{fieldHandle}_MatrixInput`:
1670
1670
1671
-
| Field | Description
1672
-
| ----------- | -----------
1673
-
| `sortOrder` | A list of all the block IDs, including any new blocks, in the order you’d like to persist after the mutation.
1674
-
| `blocks`| A list of all the actual blocks. You can omit any blocks that aren’t modified, but they must be represented on the `sortOrder` field or they’ll be deleted.
1671
+
| Field | Description
1672
+
| --- | ---
1673
+
| `sortOrder` | A list of all the nested entry IDs, including any new entries, in the order you’d like to persist after the mutation.
1674
+
| `entries`| A list of all the actual entries. You can omit any entries that aren’t modified, but they must be represented on the `sortOrder` field or they’ll be deleted.
1675
1675
1676
-
An actual block input type will contain fields for all the possible block types for this field, however, the first non-empty block will be considered in the order that the block types are defined on the field.
1677
-
1678
-
As an example, let’s pretend we have a Matrix field with a handle `ingredients`.
1679
-
1680
-
The field has three block types: `spirit`, `mixer`, and `garnish`. Each block type has one or two fields:
1676
+
As an example, let’s pretend we have a Matrix field with a handle `ingredients`. The field has three entry types: `spirit`, `mixer`, and `garnish`. Each entry type has one or two fields:
1681
1677
1682
1678
```
1683
-
ingredients
1684
-
├── spirit
1679
+
ingredients (Matrix field)
1680
+
├── spirit (Entry type)
1685
1681
│ ├── spiritName (Plain Text)
1686
1682
│ └── ounces (Number)
1687
-
├── mixer
1683
+
├── mixer (Entry type)
1688
1684
│ ├── mixerName (Plain Text)
1689
1685
│ └── ounces (Number)
1690
-
└── garnish
1686
+
└── garnish (Entry type)
1691
1687
└── garnishName (Plain Text)
1692
1688
```
1693
1689
1694
-
These are all the GraphQL input types Craft generates for this Matrix field:
1690
+
These are all the GraphQL “input types” Craft generates for this Matrix field:
1695
1691
1696
1692
| Type Name | Type Description |
1697
-
| - | -
1698
-
| `ingredients_MatrixInput` | Input type for the Matrix field, containing `sortOrder` and `blocks`.
1699
-
| `ingredients_MatrixBlockContainerInput` | Input type that represents the block, in this case containing `spirit`, `mixer`, and `garnish`.
1700
-
| `ingredients_spirit_MatrixBlockInput` | Input type for the `spirit`block, containing `spiritName` and `ounces`.
1701
-
| `ingredients_mixer_MatrixBlockInput` | Input type for the `mixer`block, containing `mixerName` and `ounces`.
1702
-
| `ingredients_garnish_MatrixBlockInput` | Input type for the `garnish`block, containing `garnishName`.
1693
+
| ---| --- |
1694
+
| `ingredients_MatrixInput` | Input type for the Matrix field, containing `sortOrder` and `entries`.
1695
+
| `ingredients_MatrixEntryContainerInput` | Input type that represents the block, in this case containing `spirit`, `mixer`, and `garnish`.
1696
+
| `ingredients_spirit_MatrixEntryInput` | Input type for `spirit`entries, containing `spiritName` and `ounces` fields.
1697
+
| `ingredients_mixer_MatrixEntryInput` | Input type for `mixer`entries, containing `mixerName` and `ounces` fields.
1698
+
| `ingredients_garnish_MatrixEntryInput` | Input type for `garnish`entries, containing the `garnishName` field.
1703
1699
1704
1700
Those input types would look like this in [GraphQL Schema Definition Language (SDL)](https://www.prisma.io/blog/graphql-sdl-schema-definition-language-6755bcb9ce51):
What field on those objects would contain data would determine the final block type.
1854
-
1855
-
::: warning
1856
-
If more than one of the block types are defined, only the block type that is listed first will be considered.
1857
-
:::
1858
-
1859
1853
### Saving Files via Mutations
1860
1854
1861
-
You can provide files for Assets as either base64-encoded data, or a URL that Craft will download.
1855
+
You can provide files for assets as either base64-encoded data, or a URL that Craft will download.
1862
1856
1863
-
Either way you’ll use the `FileInput` GraphQL input type, which has the following fields:
1857
+
Either way, you’ll use the `FileInput` GraphQL input type, which has the following fields:
1864
1858
1865
1859
| Field | Description
1866
1860
| ---------- | -----------
@@ -1872,7 +1866,11 @@ Either way you’ll use the `FileInput` GraphQL input type, which has the follow
1872
1866
1873
1867
#### Saving an Entry
1874
1868
1875
-
To save an [entry](../reference/element-types/entries.md), use the entry type-specific mutation which will have the name in the form of `save_<sectionHandle>_<entryTypeHandle>_Entry`:
1869
+
[Entries](../reference/element-types/entries.md) are created and updated with mutations named after the combination of the target section and entry type, like `save_{sectionHandle}_{typeHandle}_Entry`:
1870
+
1871
+
::: tip
1872
+
See the section on [Matrix mutations](#matrix-fields-in-mutations) for more information about saving nested entries.
1873
+
:::
1876
1874
1877
1875
<!-- BEGIN ENTRY MUTATION ARGS -->
1878
1876
@@ -1894,7 +1892,7 @@ To save an [entry](../reference/element-types/entries.md), use the entry type-sp
1894
1892
The `id`, `uid` and `authorId` arguments do not exist for single entries. This is because single entries have no authors and are identified already by the exact mutation. In a similar fashion, there are additional arguments available for structured entries. For more information, refer to [mutating structure data](#mutating-structure-data).
1895
1893
1896
1894
::: tip
1897
-
After saving an entry, Craft runs queue jobs for updating revisions and search indexes. If you’re using Craft headlessly or infrequently accessing the control panel, consider disabling <config5:runQueueAutomatically> and [establishing an always-running daemon](https://nystudio107.com/blog/robust-queue-job-handling-in-craft-cms) to keep revisions and search indexes up to date.
1895
+
After saving an entry, Craft runs queue jobs for updating revisions and search indexes. If you’re using Craft headlessly or infrequently accessing the control panel, consider disabling <config5:runQueueAutomatically> and [establishing an always-running daemon](../system/queue.md#daemon) to keep revisions and search indexes up to date.
1898
1896
:::
1899
1897
1900
1898
#### Editing Existing Entries
@@ -1903,7 +1901,7 @@ You can modify existing entries by passing the populated `id` argument to your m
1903
1901
1904
1902
#### Saving a Draft
1905
1903
1906
-
To save a draft for an entry, use the entry type-specific mutation which will have the name in the form of `save_<sectionHandle>_<entryTypeHandle>_Draft`:
1904
+
Entry _drafts_ are created and updated with mutations named after the combination of the target section and entry type, like `save_{sectionHandle}_{typeHandle}_Draft`:
1907
1905
1908
1906
<!-- BEGIN DRAFT MUTATION ARGS -->
1909
1907
@@ -1925,9 +1923,43 @@ To save a draft for an entry, use the entry type-specific mutation which will ha
1925
1923
1926
1924
#### Creating or Publishing a Draft
1927
1925
1928
-
You can use the `createDraft` mutation to save a new draft. It requires the `id` of the draft’s parent entry and returns the ID of the newly-saved draft.
1926
+
You can use the generic `createDraft` mutation to create a new draft. It requires the `id` of the draft’s canonical entry and returns the ID of the newly-saved draft:
1927
+
1928
+
::: code
1929
+
```gql Query
1930
+
mutationMyNewDraft {
1931
+
createDraft(id: 1234)
1932
+
}
1933
+
```
1934
+
```json Response
1935
+
{
1936
+
"data": {
1937
+
"createDraft": "5678"
1938
+
}
1939
+
}
1940
+
```
1941
+
:::
1942
+
1943
+
Additional (optional) arguments include a `name` for the draft, `notes`, a `creatorId` (if the draft should be created on behalf of a specific user), and a `provisional` flag. Provisional drafts (referred to in the control panel as auto-saved changes)
1944
+
1945
+
_Applying_ a draft is handled in the same way, but with the `publishDraft` mutation. It requires the `id` of the draft to be published and returns the ID of the updated canonical entry:
1946
+
1947
+
::: code
1948
+
```gql Query
1949
+
mutationPublishMyDraft {
1950
+
publishDraft(id: 5678)
1951
+
}
1952
+
```
1953
+
```json Response
1954
+
{
1955
+
"data": {
1956
+
"publishDraft": "1234"
1957
+
}
1958
+
}
1959
+
```
1960
+
:::
1929
1961
1930
-
You can publishing a draft using the `publishDraft`mutation, which requires the `id` of the draft to be published and returns the ID of the updated parent entry.
1962
+
Neither mutation accepts properties or custom field values—use the appropriate [entry mutation](#saving-an-entry) to update a draft after it has been created. To work with drafts, the [schema](#define-your-schemas) must allow creating and saving entries in the canonical entry’s section; unlike user permissions, schemas do not have discrete permissions for draft creation and canonical entry mutations.
0 commit comments