Skip to content

Commit

Permalink
add labelField, searchField type checks to relationship field
Browse files Browse the repository at this point in the history
  • Loading branch information
dcousens committed Nov 10, 2022
1 parent b03dd2d commit 3aee41f
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions packages/core/src/fields/types/relationship/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export const relationship =
...config
}: RelationshipFieldConfig<ListTypeInfo>): FieldTypeFunc<ListTypeInfo> =>
meta => {
const { fieldKey, listKey } = meta;
const { many = false } = config;
const [foreignListKey, foreignFieldKey] = ref.split('.');
const commonConfig = {
Expand Down Expand Up @@ -175,6 +176,27 @@ export const relationship =
};
}

if (!(refLabelField in foreignList.fieldsByKey)) {
throw new Error(
`The ui.labelField option for field '${fieldKey}' uses '${refLabelField}' but that field doesn't exist.`
);
}

for (const searchFieldKey of refSearchFields) {
if (!(searchFieldKey in foreignList.fieldsByKey)) {
throw new Error(
`The ui.searchFields option for relationship field '${fieldKey}' includes '${searchFieldKey}' but that field doesn't exist.`
);
}

const field = foreignList.fieldsByKey[searchFieldKey];
if (field.search) continue;

throw new Error(
`The ui.searchFields option for field '${fieldKey}' includes '${searchFieldKey}' but that field doesn't have a contains filter that accepts a GraphQL String`
);
}

return {
refFieldKey: foreignFieldKey,
refListKey: foreignListKey,
Expand Down

0 comments on commit 3aee41f

Please sign in to comment.