Skip to content

Commit

Permalink
Reduce verbosity of relationship resolution errors (#8842)
Browse files Browse the repository at this point in the history
  • Loading branch information
dcousens authored Sep 29, 2023
1 parent 98c9591 commit 60357b7
Show file tree
Hide file tree
Showing 4 changed files with 265 additions and 171 deletions.
4 changes: 1 addition & 3 deletions packages/core/src/fields/types/relationship/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,7 @@ export const relationship =
const [foreignListKey, foreignFieldKey] = ref.split('.');
const foreignList = lists[foreignListKey];
if (!foreignList) {
throw new Error(
`Unable to resolve list '${foreignListKey}' for field ${listKey}.${fieldKey}`
);
throw new Error(`${listKey}.${fieldKey} points to ${ref}, but ${ref} doesn't exist`);
}
const foreignListTypes = foreignList.types;

Expand Down
25 changes: 7 additions & 18 deletions packages/core/src/lib/core/resolve-relationships.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,32 +129,21 @@ export function resolveRelationships(
alreadyResolvedTwoSidedRelationships.add(foreignRef);
const foreignField = foreignUnresolvedList.fields[field.field]?.dbField;
if (!foreignField) {
throw new Error(
`The relationship field at ${localRef} points to ${foreignRef} but no field at ${foreignRef} exists`
);
throw new Error(`${localRef} points to ${foreignRef}, but ${foreignRef} doesn't exist`);
}

if (foreignField.kind !== 'relation') {
throw new Error(
`The relationship field at ${localRef} points to ${foreignRef} but ${foreignRef} is not a relationship field`
);
}

if (foreignField.list !== listKey) {
throw new Error(
`The relationship field at ${localRef} points to ${foreignRef} but ${foreignRef} points to the list ${foreignField.list} rather than ${listKey}`
);
}

if (foreignField.field === undefined) {
throw new Error(
`The relationship field at ${localRef} points to ${foreignRef}, ${localRef} points to ${listKey} correctly but does not point to the ${fieldPath} field when it should`
`${localRef} points to ${foreignRef}, but ${foreignRef} is not a relationship field`
);
}

if (foreignField.field !== fieldPath) {
const actualRef = foreignField.field
? `${foreignField.list}.${foreignField.field}`
: foreignField.list;
if (actualRef !== localRef) {
throw new Error(
`The relationship field at ${localRef} points to ${foreignRef}, ${localRef} points to ${listKey} correctly but points to the ${foreignField.field} field instead of ${fieldPath}`
`${localRef} points to ${foreignRef}, ${foreignRef} points to ${actualRef}, expected ${foreignRef} to point to ${localRef}`
);
}

Expand Down

This file was deleted.

Loading

0 comments on commit 60357b7

Please sign in to comment.