Schema tutorialLesson 7: Adapting content in bulk
Lesson 7: Adapting content in bulk
This tutorial lesson adapts content in bulk, updating the title, content and excerpt for multiple posts with a single GraphQL request.
For this GraphQL query to work, the Schema Configuration applied to the endpoint needs to have Nested Mutations enabled
The GraphQL query below retrieves the data for the multiple posts, executes a search and replace on the title
, content
and excerpt
fields for each of them, adapts these as inputs to the mutation, and exports a single dynamic variable $postInputs
with all the results as a dictionary, with format:
In the mutation
operation, each of these entries is then retrieved via _objectProperty
(using ${post ID}
as the key) and passed as the input
to update the post:
- The Field on Field extension provides directive
@applyField
which, invoked with_objectProperty
, extracts the properties from each item in the JSON object (passed as$adaptedSource
), and then with_echo
, it creates the corresponding JSON input with those properties - In addition to function fields, the PHP Functions via Schema extension also provides functionality via their corresponding "function directives", such as
@strReplaceMultiple
- When Multi-Field Directives is enabled, we can apply a directive to more than one field, indicating the relative position(s) of the additional field(s) via argument
affectAdditionalFieldsUnderPos
- When applying a directive to some field and then exporting its value, we must use
@deferredExport
instead of@export
- When using Multi-Field Directives together with
@export
( or@deferredExport
), the exported value is a JSON object containing all the fields - Mutation
Post.update
is available in the schema only when the Nested Mutations feature is enabled