From f67497c1a9dd7462e7d6564250712f5456dc5cb0 Mon Sep 17 00:00:00 2001 From: Tim Leslie Date: Tue, 13 Apr 2021 11:01:57 +1000 Subject: [PATCH] Remove support for aux lists (#5443) --- .changeset/proud-apricots-punch.md | 5 +++++ packages/keystone/lib/Keystone/index.js | 13 ++---------- packages/keystone/lib/ListTypes/list.js | 23 ++------------------- packages/keystone/lib/providers/listCRUD.js | 19 ++++++----------- 4 files changed, 15 insertions(+), 45 deletions(-) create mode 100644 .changeset/proud-apricots-punch.md diff --git a/.changeset/proud-apricots-punch.md b/.changeset/proud-apricots-punch.md new file mode 100644 index 00000000000..8610f5cd0d7 --- /dev/null +++ b/.changeset/proud-apricots-punch.md @@ -0,0 +1,5 @@ +--- +'@keystone-next/keystone-legacy': major +--- + +Removed legacy support for auxilliary lists. diff --git a/packages/keystone/lib/Keystone/index.js b/packages/keystone/lib/Keystone/index.js index 2093e97e1a9..bf4f47ffa3d 100644 --- a/packages/keystone/lib/Keystone/index.js +++ b/packages/keystone/lib/Keystone/index.js @@ -34,9 +34,9 @@ module.exports = class Keystone { } } - createList(key, config, { isAuxList = false } = {}) { + createList(key, config) { const { getListByKey, adapter } = this; - const isReservedName = !isAuxList && key[0] === '_'; + const isReservedName = key[0] === '_'; if (isReservedName) { throw new Error(`Invalid list name "${key}". List names cannot start with an underscore.`); @@ -61,15 +61,6 @@ module.exports = class Keystone { adapter, defaultAccess: this.defaultAccess, registerType: type => this.registeredTypes.add(type), - isAuxList, - createAuxList: (auxKey, auxConfig) => { - if (isAuxList) { - throw new Error( - `Aux list "${key}" shouldn't be creating more aux lists ("${auxKey}"). Something's probably not right here.` - ); - } - return this.createList(auxKey, auxConfig, { isAuxList: true }); - }, }); this.lists[key] = list; this.listsArray.push(list); diff --git a/packages/keystone/lib/ListTypes/list.js b/packages/keystone/lib/ListTypes/list.js index c63208ef24e..d0ea0ed5928 100644 --- a/packages/keystone/lib/ListTypes/list.js +++ b/packages/keystone/lib/ListTypes/list.js @@ -43,7 +43,7 @@ module.exports = class List { queryLimits = {}, cacheHint, }, - { getListByKey, adapter, defaultAccess, registerType, createAuxList, isAuxList } + { getListByKey, adapter, defaultAccess, registerType } ) { this.key = key; this._fields = fields; @@ -59,7 +59,6 @@ module.exports = class List { ...adminConfig, }; - this.isAuxList = isAuxList; this.getListByKey = getListByKey; this.defaultAccess = defaultAccess; @@ -132,23 +131,6 @@ module.exports = class List { // Tell Keystone about all the types we've seen Object.values(fields).forEach(({ type }) => registerType(type)); - - this.createAuxList = (auxKey, auxConfig) => - createAuxList(auxKey, { - access: Object.entries(this.access) - .filter(([key]) => key !== 'internal') - .reduce( - (acc, [schemaName, access]) => ({ - ...acc, - [schemaName]: Object.entries(access).reduce( - (acc, [op, rule]) => ({ ...acc, [op]: !!rule }), // Reduce the entries to truthy values - {} - ), - }), - {} - ), - ...auxConfig, - }); } initFields() { @@ -164,7 +146,7 @@ module.exports = class List { // Helpful errors for misconfigured lists Object.entries(sanitisedFieldsConfig).forEach(([fieldKey, fieldConfig]) => { - if (!this.isAuxList && fieldKey[0] === '_') { + if (fieldKey[0] === '_') { throw new Error( `Invalid field name "${fieldKey}". Field names cannot start with an underscore.` ); @@ -191,7 +173,6 @@ module.exports = class List { listAdapter: this.adapter, fieldAdapterClass: type.adapter, defaultAccess: this.defaultAccess.field, - createAuxList: this.createAuxList, schemaNames: this._schemaNames, }) ); diff --git a/packages/keystone/lib/providers/listCRUD.js b/packages/keystone/lib/providers/listCRUD.js index f2206f97114..bab3169331c 100644 --- a/packages/keystone/lib/providers/listCRUD.js +++ b/packages/keystone/lib/providers/listCRUD.js @@ -20,19 +20,15 @@ class ListCRUDProvider { } getQueries({ schemaName }) { - // Aux lists are only there for typing and internal operations, they should - // not have any GraphQL operations performed on them - const firstClassLists = this.lists.filter(list => !list.isAuxList); return [ - ...flatten(firstClassLists.map(list => list.getGqlQueries({ schemaName }))), + ...flatten(this.lists.map(list => list.getGqlQueries({ schemaName }))), `""" Retrieve the meta-data for all lists. """ ${this.gqlNames.listsMeta}(where: ${this.gqlNames.listsMetaInput}): [_ListMeta]`, ]; } getMutations({ schemaName }) { - const firstClassLists = this.lists.filter(list => !list.isAuxList); - return flatten(firstClassLists.map(list => list.getGqlMutations({ schemaName }))); + return flatten(this.lists.map(list => list.getGqlMutations({ schemaName }))); } getSubscriptions({}) { @@ -85,7 +81,6 @@ class ListCRUDProvider { // self-referential field (eg: User { friends: [User] }) relatedFields: ({ key }) => this.lists - .filter(list => !list.isAuxList) .map(list => ({ type: list.gqlNames.outputTypeName, fields: flatten( @@ -110,12 +105,11 @@ class ListCRUDProvider { } getQueryResolvers({ schemaName }) { - const firstClassLists = this.lists.filter(list => !list.isAuxList); return { // Order is also important here, any TypeQuery's defined by types // shouldn't be able to override list-level queries - ...objMerge(firstClassLists.map(list => list.gqlAuxQueryResolvers())), - ...objMerge(firstClassLists.map(list => list.gqlQueryResolvers({ schemaName }))), + ...objMerge(this.lists.map(list => list.gqlAuxQueryResolvers())), + ...objMerge(this.lists.map(list => list.gqlQueryResolvers({ schemaName }))), // And the Keystone meta queries must always be available [this.gqlNames.listsMeta]: (_, { where: { key, auxiliary } = {} }, context) => @@ -124,15 +118,14 @@ class ListCRUDProvider { list => list.access[schemaName].read && (!key || list.key === key) && - (auxiliary === undefined || list.isAuxList === auxiliary) + (auxiliary === undefined || auxiliary === false) ) .map(list => list.listMeta(context)), }; } getMutationResolvers({ schemaName }) { - const firstClassLists = this.lists.filter(list => !list.isAuxList); - return objMerge(firstClassLists.map(list => list.gqlMutationResolvers({ schemaName }))); + return objMerge(this.lists.map(list => list.gqlMutationResolvers({ schemaName }))); } getSubscriptionResolvers({}) {