Skip to content

Commit

Permalink
Remove legacy default ID support (#5320)
Browse files Browse the repository at this point in the history
* Remove legacy default ID support

* Fix tests
  • Loading branch information
timleslie authored Mar 31, 2021
1 parent 5c4b486 commit fda8286
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 39 deletions.
7 changes: 7 additions & 0 deletions .changeset/shy-dancers-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@keystone-next/adapter-prisma-legacy': major
'@keystone-next/fields-auto-increment-legacy': major
'@keystone-next/keystone-legacy': major
---

Removed legacy default ID field support.
1 change: 0 additions & 1 deletion packages/adapter-prisma/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"node": ">=10.0.0"
},
"dependencies": {
"@keystone-next/fields-auto-increment-legacy": "^9.0.0",
"@keystone-next/keystone-legacy": "^22.0.0",
"@keystone-next/utils-legacy": "^8.0.0",
"p-waterfall": "^2.1.1"
Expand Down
6 changes: 0 additions & 6 deletions packages/adapter-prisma/src/adapter-prisma.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,6 @@ class PrismaAdapter {
return this.prisma.$disconnect();
}

getDefaultPrimaryKeyConfig() {
// Required here due to circular refs
const { AutoIncrement } = require('@keystone-next/fields-auto-increment-legacy');
return AutoIncrement.primaryKeyDefaults[this.name].getConfig();
}

async checkDatabaseVersion() {
// FIXME: Decide what/how we want to check things here
}
Expand Down
7 changes: 0 additions & 7 deletions packages/fields-auto-increment/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,4 @@ export const AutoIncrement = {
adapters: {
prisma: PrismaAutoIncrementInterface,
},

primaryKeyDefaults: {
prisma: {
// Uniqueness, non-nullability and GraphQL type are implied
getConfig: () => ({ type: AutoIncrement }),
},
},
};
13 changes: 1 addition & 12 deletions packages/keystone/lib/ListTypes/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,18 +165,7 @@ module.exports = class List {

// Add an 'id' field if none supplied
if (!sanitisedFieldsConfig.id) {
if (typeof this.adapter.parentAdapter.getDefaultPrimaryKeyConfig !== 'function') {
throw new Error(
`No 'id' field given for the '${this.key}' list and the list adapter ` +
`in used (${this.adapter.key}) doesn't supply a default primary key config ` +
`(no 'getDefaultPrimaryKeyConfig()' function)`
);
}
// Rebuild the object so id is "first"
sanitisedFieldsConfig = {
id: this.adapter.parentAdapter.getDefaultPrimaryKeyConfig(),
...sanitisedFieldsConfig,
};
throw new Error(`No 'id' field given for the '${this.key}' list.`);
}

// Helpful errors for misconfigured lists
Expand Down
2 changes: 1 addition & 1 deletion packages/keystone/tests/Keystone.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ class MockListAdapter {
class MockAdapter {
name = 'mock';
newListAdapter = () => new MockListAdapter(this);
getDefaultPrimaryKeyConfig = () => ({ type: MockFieldType });
}

test('Check require', () => {
Expand All @@ -70,6 +69,7 @@ describe('Keystone.createList()', () => {

keystone.createList('User', {
fields: {
id: { type: MockFieldType },
name: { type: MockFieldType },
email: { type: MockFieldType },
},
Expand Down
24 changes: 12 additions & 12 deletions packages/keystone/tests/List.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,6 @@ const context = {
// Needs to be wrapped in a mock type for gql to correctly parse it.
const normalise = s => print(gql(`type t { ${s} }`));

const config = {
fields: {
name: { type: Text },
email: { type: Text },
other: { type: Relationship, ref: 'Other' },
hidden: { type: Text, access: { read: false, create: true, update: true, delete: true } },
writeOnce: { type: Text, access: { read: true, create: true, update: false, delete: true } },
},
};

const getListByKey = listKey => {
if (listKey === 'Other') {
return {
Expand Down Expand Up @@ -164,7 +154,6 @@ class MockListAdapter {
class MockAdapter {
name = 'mock';
newListAdapter = () => new MockListAdapter(this);
getDefaultPrimaryKeyConfig = () => ({ type: MockIdType });
}

const listExtras = () => ({
Expand All @@ -175,6 +164,17 @@ const listExtras = () => ({
schemaNames: ['public'],
});

const config = {
fields: {
id: { type: MockIdType },
name: { type: Text },
email: { type: Text },
other: { type: Relationship, ref: 'Other' },
hidden: { type: Text, access: { read: false, create: true, update: true, delete: true } },
writeOnce: { type: Text, access: { read: true, create: true, update: false, delete: true } },
},
};

const setup = extraConfig => {
const list = new List('Test', { ...config, ...extraConfig }, listExtras());
list.initFields();
Expand Down Expand Up @@ -277,7 +277,7 @@ describe('new List()', () => {
expect(list.fieldsByPath['hidden']).toBeInstanceOf(Text.implementation);
expect(list.fieldsByPath['writeOnce']).toBeInstanceOf(Text.implementation);

const idOnlyList = new List('NoField', { fields: {} }, listExtras());
const idOnlyList = new List('NoField', { fields: { id: { type: MockIdType } } }, listExtras());
idOnlyList.initFields();
expect(idOnlyList.fields).toHaveLength(1);
expect(list.fields[0]).toBeInstanceOf(MockIdType.implementation);
Expand Down

0 comments on commit fda8286

Please sign in to comment.