Back to Content Management API

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 current revisionId.
    • dataPatch: [SectionDataPatchOperationInput!] Operations on data, applied in order. Each has op: SectionDataPatchOperationType! (ADD, REMOVE, REPLACE, or TEST), path: String!, and value: JSON.
    • stylesPatch: [SectionDataPatchOperationInput!] Operations on styles, in the same format.
    • dataSourcePatch: [SectionDataPatchOperationInput!] Operations on dataSource, in the same format.
    • title: String A 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"
      }
    }
  }
}

Was this page helpful?