fix: omit empty optional image fields#7167
Conversation
🦋 Changeset detectedLatest commit: ece9c05 The changes in this PR will be included in the next version bump. This PR includes changesets to release 15 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
joshbermanssw
left a comment
There was a problem hiding this comment.
Requesting changes for the update clear case.
| throw new Error(`Expected to find field by name ${fieldName}`); | ||
| } | ||
| if (isEmptyOptionalImageValue(fieldValue, field)) { | ||
| continue; |
There was a problem hiding this comment.
Requesting changes here: this handles a blank optional image by omitting the field from the mutation values, but update persistence later merges those values back onto the existing document ({ ...legacyValues, ...params } in resolveUpdateDocument() and { ...oldDoc, ...values } in the deprecated update path). That means an existing coverImage: "foo.png" followed by an editor submit of coverImage: "" can produce empty mutation values for this field and preserve the old image instead of clearing it from frontmatter. Please add coverage for clearing an existing optional image on update and make the explicit clear remove the key from the merged payload, while keeping truly omitted fields as unchanged.
|
Fixed the update clear case. Empty optional image values are still omitted on create, but now clear an existing image on update. Added a resolver regression test for that path. |
| }; | ||
| break; | ||
| case 'image': | ||
| if (isEmptyOptionalImageValue(value, field)) { |
There was a problem hiding this comment.
Question on this one: why change the read path too?
The frontmatter bug only needs the write path. This makes an existing document with avatar: '' return null instead of "" over GraphQL, which is an API-visible change for existing content shipping as a patch.
If it's load-bearing for something I've missed, could you note it in the changeset? If not, dropping it would make the PR strictly safer.
Fixes #5229.
Omit empty optional image fields from document payloads so blank image fields are not written to frontmatter.
Tests: