Skip to content

Commit

Permalink
Split create/update field input resolvers for relationship fields (#6317
Browse files Browse the repository at this point in the history
)
  • Loading branch information
timleslie authored Aug 16, 2021
1 parent 81b95c5 commit 1cbcf54
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/brown-plums-kneel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-next/keystone': patch
---

Separated the resolving of non-relationship field from relationship fields in create/update inputs to allow for better error handling.
23 changes: 17 additions & 6 deletions packages/keystone/src/lib/core/mutations/create-update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,21 +180,32 @@ async function getResolvedData(
);
}

// Apply field type input resolvers
// Apply non-relationship field type input resolvers
resolvedData = Object.fromEntries(
await promiseAllRejectWithAllErrors(
Object.entries(list.fields).map(async ([fieldKey, field]) => {
const inputResolver = field.input?.[operation]?.resolve;
let input = resolvedData[fieldKey];
if (inputResolver) {
if (inputResolver && field.dbField.kind !== 'relation') {
input = await inputResolver(input, context, undefined);
}
return [fieldKey, input] as const;
})
)
);

// Apply relationship field type input resolvers
resolvedData = Object.fromEntries(
await promiseAllRejectWithAllErrors(
Object.entries(list.fields).map(async ([fieldKey, field]) => {
const inputResolver = field.input?.[operation]?.resolve;
let input = resolvedData[fieldKey];
if (inputResolver && field.dbField.kind === 'relation') {
input = await inputResolver(
input,
context,
// This third argument only applies to relationship fields
(() => {
// This third argument only applies to relationship fields
if (field.dbField.kind !== 'relation') {
return undefined;
}
if (input === undefined) {
// No-op: This is what we want
return () => undefined;
Expand Down

0 comments on commit 1cbcf54

Please sign in to comment.