Skip to content

Commit

Permalink
Remove unqueryable lists from admin meta (#6512)
Browse files Browse the repository at this point in the history
* update createAdminMeta to not include lists with graphql querying disabled. also appy this to relationships to those omitted lists

* chnageset

* Update .changeset/twelve-apples-happen.md

Co-authored-by: Tim Leslie <[email protected]>

Co-authored-by: Tim Leslie <[email protected]>
  • Loading branch information
gwyneplaine and timleslie authored Sep 9, 2021
1 parent 919eaa9 commit bf58744
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/twelve-apples-happen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-next/keystone': patch
---

Fixed lists with `graphql.omit: ['query']` causing issues in the Admin UI.
18 changes: 18 additions & 0 deletions packages/keystone/src/admin-ui/system/createAdminMeta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,17 @@ export function createAdminMeta(
views: [],
};

const omittedLists: string[] = [];

for (const [key, list] of Object.entries(initialisedLists)) {
const listConfig = lists[key];
if (list.graphql.isEnabled.query === false) {
// If graphql querying is disabled on the list,
// push the key into the ommittedLists array for use further down in the procedure and skip.
omittedLists.push(key);

continue;
}
// Default the labelField to `name`, `label`, or `title` if they exist; otherwise fall back to `id`
const labelField =
(listConfig.ui?.labelField as string | undefined) ??
Expand Down Expand Up @@ -80,6 +89,7 @@ export function createAdminMeta(
}
// Populate .fields array
for (const [key, list] of Object.entries(initialisedLists)) {
if (omittedLists.includes(key)) continue;
const searchFields = new Set(config.lists[key].ui?.searchFields ?? []);
if (searchFields.has('id')) {
throw new Error(
Expand All @@ -98,6 +108,8 @@ export function createAdminMeta(
}

for (const [fieldKey, field] of Object.entries(list.fields)) {
// If the field is a relationship field and is related to an omitted list, skip.
if (field.dbField.kind === 'relation' && omittedLists.includes(field.dbField.list)) continue;
// FIXME: Disabling this entirely for now until the Admin UI can properly
// handle `omit: ['read']` correctly.
if (field.graphql.isEnabled.read === false) continue;
Expand Down Expand Up @@ -130,7 +142,13 @@ export function createAdminMeta(
// we do this seperately to the above so that fields can check other fields to validate their config or etc.
// (ofc they won't necessarily be able to see other field's fieldMeta)
for (const [key, list] of Object.entries(initialisedLists)) {
if (list.graphql.isEnabled.query === false) continue;
for (const fieldMetaRootVal of adminMetaRoot.listsByKey[key].fields) {
const dbField = list.fields[fieldMetaRootVal.path].dbField;
// If the field is a relationship field and is related to an omitted list, skip.
if (dbField.kind === 'relation' && omittedLists.includes(dbField.list)) {
continue;
}
fieldMetaRootVal.fieldMeta =
list.fields[fieldMetaRootVal.path].getAdminMeta?.(adminMetaRoot) ?? null;
}
Expand Down

0 comments on commit bf58744

Please sign in to comment.