Skip to content

Commit

Permalink
Remove support for aux lists (#5443)
Browse files Browse the repository at this point in the history
  • Loading branch information
timleslie committed Apr 13, 2021
1 parent 1d85d7f commit f67497c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 45 deletions.
5 changes: 5 additions & 0 deletions .changeset/proud-apricots-punch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-next/keystone-legacy': major
---

Removed legacy support for auxilliary lists.
13 changes: 2 additions & 11 deletions packages/keystone/lib/Keystone/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.`);
Expand All @@ -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);
Expand Down
23 changes: 2 additions & 21 deletions packages/keystone/lib/ListTypes/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -59,7 +59,6 @@ module.exports = class List {
...adminConfig,
};

this.isAuxList = isAuxList;
this.getListByKey = getListByKey;
this.defaultAccess = defaultAccess;

Expand Down Expand Up @@ -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() {
Expand All @@ -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.`
);
Expand All @@ -191,7 +173,6 @@ module.exports = class List {
listAdapter: this.adapter,
fieldAdapterClass: type.adapter,
defaultAccess: this.defaultAccess.field,
createAuxList: this.createAuxList,
schemaNames: this._schemaNames,
})
);
Expand Down
19 changes: 6 additions & 13 deletions packages/keystone/lib/providers/listCRUD.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({}) {
Expand Down Expand Up @@ -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(
Expand All @@ -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) =>
Expand All @@ -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({}) {
Expand Down

1 comment on commit f67497c

@vercel
Copy link

@vercel vercel bot commented on f67497c Apr 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.