sectionPatch
Applies JSON Patch-style operations to a section's data, styles, or dataSource, or renames it, without resending the whole section. Read the section's current revisionId first and pass it as expectedRevisionId. If the section changed since then, the mutation fails with a conflict error instead of overwriting the newer edit.
Supply at least one of dataPatch, stylesPatch, dataSourcePatch, or title. Paths are JSON Pointers relative to the field being patched, such as /heading in dataPatch. Use a TEST operation to assert a value before changing it. After patching, data must still be an object, styles and dataSource must be an object or null, and dataSource must be valid.
For a section with a metaobject data source, dataPatch starts from the metaobject's current fields, and the store needs a connected Shopify account. Outside a content release, a change to data also updates the metaobject in Shopify. Use sectionUpsert to create a section.
Arguments
- Name
input- Type
- SectionPatchInput!
- Description
An object.
id:ID!The ID of the section.expectedRevisionId:ID!The section's currentrevisionId.dataPatch:[SectionDataPatchOperationInput!]Operations ondata, applied in order. Each hasop: SectionDataPatchOperationType!(ADD,REMOVE,REPLACE, orTEST),path: String!, andvalue: JSON.stylesPatch:[SectionDataPatchOperationInput!]Operations onstyles, in the same format.dataSourcePatch:[SectionDataPatchOperationInput!]Operations ondataSource, in the same format.title:StringA new title. Must not be empty.
Returns
- Name
Section.*- Type
- Section!
- Description
Any requested field from the Section object.
Request
import { PackClient } from '@pack/client'
const packClient = new PackClient({
token: 'YOUR-PACK-TOKEN',
})
const query = `
mutation SectionPatch($input: SectionPatchInput!) {
sectionPatch(input: $input) {
id
revisionId
data
}
}
`
const variables = {
input: {
id: 'section-id',
expectedRevisionId: 'current-revision-id',
dataPatch: [
{
op: 'TEST',
path: '/heading',
value: 'Old heading',
},
{
op: 'REPLACE',
path: '/heading',
value: 'New heading',
},
],
},
}
const response = await packClient.fetch(query, { variables })
console.log(response.data)
Response
{
"data": {
"sectionPatch": {
"id": "section-id",
"revisionId": "new-revision-id",
"data": {
"_template": "hero",
"heading": "New heading"
}
}
}
}