Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce verbosity of relationship resolution errors #8842

Merged
merged 5 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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