From 7ead553c0761d0ca2dcd44e9a15e215a2b98ef06 Mon Sep 17 00:00:00 2001 From: Tim Leslie Date: Mon, 17 May 2021 10:57:46 +1000 Subject: [PATCH 1/3] Fix use of disconnect --- .../crud-self-ref/one-to-many-one-sided.test.ts | 4 ++-- .../relationships/crud-self-ref/one-to-one.test.ts | 4 ++-- .../relationships/crud/one-to-many-one-sided.test.ts | 2 +- .../api-tests/relationships/crud/one-to-one.test.ts | 4 ++-- .../nested-mutations/disconnect-all-singular.test.ts | 8 ++++---- .../nested-mutations/disconnect-singular.test.ts | 12 +++++------- 6 files changed, 16 insertions(+), 18 deletions(-) diff --git a/tests/api-tests/relationships/crud-self-ref/one-to-many-one-sided.test.ts b/tests/api-tests/relationships/crud-self-ref/one-to-many-one-sided.test.ts index a55cff1cb80..e22044d818b 100644 --- a/tests/api-tests/relationships/crud-self-ref/one-to-many-one-sided.test.ts +++ b/tests/api-tests/relationships/crud-self-ref/one-to-many-one-sided.test.ts @@ -247,7 +247,7 @@ multiAdapterRunners().map(({ runner, provider }) => // Run the query to disconnect the location from company const _user = await context.lists.User.updateOne({ id: user.id, - data: { friend: { disconnect: { id: friend.id } } }, + data: { friend: null }, query: 'id friend { id name }', }); expect(_user.id).toEqual(user.id); @@ -268,7 +268,7 @@ multiAdapterRunners().map(({ runner, provider }) => // Run the query to disconnect the location from company const _user = await context.lists.User.updateOne({ id: user.id, - data: { friend: { disconnectAll: true } }, + data: { friend: null }, query: 'id friend { id name }', }); expect(_user.id).toEqual(user.id); diff --git a/tests/api-tests/relationships/crud-self-ref/one-to-one.test.ts b/tests/api-tests/relationships/crud-self-ref/one-to-one.test.ts index 0355a8e33ee..b3d9b1ec061 100644 --- a/tests/api-tests/relationships/crud-self-ref/one-to-one.test.ts +++ b/tests/api-tests/relationships/crud-self-ref/one-to-one.test.ts @@ -367,7 +367,7 @@ multiAdapterRunners().map(({ runner, provider }) => // Run the query to disconnect the location from company const _user = await context.lists.User.updateOne({ id: user.id, - data: { friend: { disconnect: { id: friend.id } } }, + data: { friend: null }, query: 'id friend { id name }', }); @@ -390,7 +390,7 @@ multiAdapterRunners().map(({ runner, provider }) => // Run the query to disconnect the location from company const _user = await context.lists.User.updateOne({ id: user.id, - data: { friend: { disconnectAll: true } }, + data: { friend: null }, query: 'id friend { id name }', }); diff --git a/tests/api-tests/relationships/crud/one-to-many-one-sided.test.ts b/tests/api-tests/relationships/crud/one-to-many-one-sided.test.ts index 886153df11c..61548357ac2 100644 --- a/tests/api-tests/relationships/crud/one-to-many-one-sided.test.ts +++ b/tests/api-tests/relationships/crud/one-to-many-one-sided.test.ts @@ -311,7 +311,7 @@ multiAdapterRunners().map(({ runner, provider }) => // Run the query to disconnect the location from company const _company = await context.lists.Company.updateOne({ id: company.id, - data: { location: { disconnectAll: true } }, + data: { location: null }, query: 'id location { id name }', }); expect(_company.id).toEqual(company.id); diff --git a/tests/api-tests/relationships/crud/one-to-one.test.ts b/tests/api-tests/relationships/crud/one-to-one.test.ts index 09cc33b66dc..1bd4d4b30fa 100644 --- a/tests/api-tests/relationships/crud/one-to-one.test.ts +++ b/tests/api-tests/relationships/crud/one-to-one.test.ts @@ -858,7 +858,7 @@ multiAdapterRunners().map(({ runner, provider }) => // Run the query to disconnect the location from company const _company = await context.lists.Company.updateOne({ id: company.id, - data: { location: { disconnectAll: true } }, + data: { location: null }, query: 'id location { id name }', }); expect(_company.id).toEqual(company.id); @@ -880,7 +880,7 @@ multiAdapterRunners().map(({ runner, provider }) => // Run the query to disconnect the location from company const _location = await context.lists.Location.updateOne({ id: location.id, - data: { company: { disconnectAll: true } }, + data: { company: null }, query: 'id company { id name }', }); expect(_location.id).toEqual(location.id); diff --git a/tests/api-tests/relationships/nested-mutations/disconnect-all-singular.test.ts b/tests/api-tests/relationships/nested-mutations/disconnect-all-singular.test.ts index 16951dce779..027c2764af9 100644 --- a/tests/api-tests/relationships/nested-mutations/disconnect-all-singular.test.ts +++ b/tests/api-tests/relationships/nested-mutations/disconnect-all-singular.test.ts @@ -68,7 +68,7 @@ multiAdapterRunners().map(({ runner, provider }) => // Update the item and link the relationship field const event = await context.lists.Event.updateOne({ id: createEvent.id, - data: { group: { disconnectAll: true } }, + data: { group: null }, query: 'id group { id }', }); @@ -89,7 +89,7 @@ multiAdapterRunners().map(({ runner, provider }) => runner(setupKeystone, async ({ context }) => { // Create an item that does the linking const event = await context.lists.Event.createOne({ - data: { group: { disconnectAll: true } }, + data: { group: null }, query: 'id group { id }', }); @@ -106,7 +106,7 @@ multiAdapterRunners().map(({ runner, provider }) => // Create an item that does the linking const event = await context.lists.Event.updateOne({ id: createEvent.id, - data: { group: { disconnectAll: true } }, + data: { group: null }, query: 'id group { id }', }); @@ -140,7 +140,7 @@ multiAdapterRunners().map(({ runner, provider }) => // Update the item and link the relationship field await context.exitSudo().lists.EventToGroupNoRead.updateOne({ id: createEvent.id, - data: { group: { disconnectAll: true } }, + data: { group: null }, }); // Avoid false-positives by checking the database directly diff --git a/tests/api-tests/relationships/nested-mutations/disconnect-singular.test.ts b/tests/api-tests/relationships/nested-mutations/disconnect-singular.test.ts index 52b59b036c4..d3546bef77f 100644 --- a/tests/api-tests/relationships/nested-mutations/disconnect-singular.test.ts +++ b/tests/api-tests/relationships/nested-mutations/disconnect-singular.test.ts @@ -71,7 +71,7 @@ multiAdapterRunners().map(({ runner, provider }) => // Update the item and link the relationship field const event = await context.lists.Event.updateOne({ id: createEvent.id, - data: { group: { disconnect: { id: createGroup.id } } }, + data: { group: null }, query: 'id group { id }', }); @@ -90,11 +90,9 @@ multiAdapterRunners().map(({ runner, provider }) => test( 'silently succeeds if used during create', runner(setupKeystone, async ({ context }) => { - const FAKE_ID = '5b84f38256d3c2df59a0d9bf'; - // Create an item that does the linking const event = await context.lists.Event.createOne({ - data: { group: { disconnect: { id: FAKE_ID } } }, + data: { group: null }, query: 'id group { id }', }); @@ -102,7 +100,7 @@ multiAdapterRunners().map(({ runner, provider }) => }) ); - test( + test.skip( 'silently succeeds if no item to disconnect during update', runner(setupKeystone, async ({ context }) => { const FAKE_ID = '5b84f38256d3c2df59a0d9bf'; @@ -122,7 +120,7 @@ multiAdapterRunners().map(({ runner, provider }) => }) ); - test( + test.skip( 'silently succeeds if item to disconnect does not match during update', runner(setupKeystone, async ({ context }) => { const groupName = `foo${sampleOne(alphanumGenerator)}`; @@ -172,7 +170,7 @@ multiAdapterRunners().map(({ runner, provider }) => // Update the item and link the relationship field await context.exitSudo().lists.EventToGroupNoRead.updateOne({ id: createEvent.id, - data: { group: { disconnect: { id: createGroup.id } } }, + data: { group: null }, }); // Avoid false-positives by checking the database directly From ffa4deca3684d8800cb0346bcf9997955f2ad1e8 Mon Sep 17 00:00:00 2001 From: Tim Leslie Date: Mon, 17 May 2021 11:17:57 +1000 Subject: [PATCH 2/3] Fix disconnect usage --- .../crud-self-ref/many-to-many.test.ts | 6 +++--- .../crud-self-ref/one-to-many-one-sided.test.ts | 13 +++++-------- .../relationships/crud-self-ref/one-to-one.test.ts | 6 +++--- .../crud/one-to-many-one-sided.test.ts | 2 +- .../api-tests/relationships/crud/one-to-one.test.ts | 4 ++-- .../create-and-connect-many.test.ts | 6 +++--- .../nested-mutations/create-many.test.ts | 4 ++-- .../nested-mutations/create-singular.test.ts | 2 +- .../nested-mutations/disconnect-all-many.test.ts | 2 +- 9 files changed, 21 insertions(+), 24 deletions(-) diff --git a/tests/api-tests/relationships/crud-self-ref/many-to-many.test.ts b/tests/api-tests/relationships/crud-self-ref/many-to-many.test.ts index 48fda248965..21fc1ac8a5c 100644 --- a/tests/api-tests/relationships/crud-self-ref/many-to-many.test.ts +++ b/tests/api-tests/relationships/crud-self-ref/many-to-many.test.ts @@ -12,9 +12,9 @@ const alphanumGenerator = gen.alphaNumString.notEmpty(); const createInitialData = async (context: KeystoneContext) => { const users = await context.lists.User.createMany({ data: [ - { data: { name: sampleOne(alphanumGenerator) } }, - { data: { name: sampleOne(alphanumGenerator) } }, - { data: { name: sampleOne(alphanumGenerator) } }, + { name: sampleOne(alphanumGenerator) }, + { name: sampleOne(alphanumGenerator) }, + { name: sampleOne(alphanumGenerator) }, ], }); diff --git a/tests/api-tests/relationships/crud-self-ref/one-to-many-one-sided.test.ts b/tests/api-tests/relationships/crud-self-ref/one-to-many-one-sided.test.ts index e22044d818b..a1ec9750f80 100644 --- a/tests/api-tests/relationships/crud-self-ref/one-to-many-one-sided.test.ts +++ b/tests/api-tests/relationships/crud-self-ref/one-to-many-one-sided.test.ts @@ -38,10 +38,10 @@ const createUserAndFriend = async (context: KeystoneContext) => { const createComplexData = async (context: KeystoneContext) => { const users = await context.lists.User.createMany({ data: [ - { data: { name: 'A', friend: { create: { name: 'A1' } } } }, - { data: { name: 'B', friend: { create: { name: 'D1' } } } }, - { data: { name: 'C', friend: { create: { name: 'B1' } } } }, - { data: { name: 'E' } }, + { name: 'A', friend: { create: { name: 'A1' } } }, + { name: 'B', friend: { create: { name: 'D1' } } }, + { name: 'C', friend: { create: { name: 'B1' } } }, + { name: 'E' }, ], query: 'id name friend { id name }', }); @@ -54,10 +54,7 @@ const createComplexData = async (context: KeystoneContext) => { expect(users[3].name).toEqual('E'); expect(users[3].friend).toBe(null); const _users = await context.lists.User.createMany({ - data: [ - { data: { name: 'D', friend: { connect: { id: users[2].friend.id } } } }, - { data: { name: 'C1' } }, - ], + data: [{ name: 'D', friend: { connect: { id: users[2].friend.id } } }, { name: 'C1' }], query: 'id name friend { id name }', }); expect(_users[0].name).toEqual('D'); diff --git a/tests/api-tests/relationships/crud-self-ref/one-to-one.test.ts b/tests/api-tests/relationships/crud-self-ref/one-to-one.test.ts index b3d9b1ec061..9b1fd87a6c2 100644 --- a/tests/api-tests/relationships/crud-self-ref/one-to-one.test.ts +++ b/tests/api-tests/relationships/crud-self-ref/one-to-one.test.ts @@ -12,9 +12,9 @@ const alphanumGenerator = gen.alphaNumString.notEmpty(); const createInitialData = async (context: KeystoneContext) => { const users = await context.lists.User.createMany({ data: [ - { data: { name: sampleOne(alphanumGenerator) } }, - { data: { name: sampleOne(alphanumGenerator) } }, - { data: { name: sampleOne(alphanumGenerator) } }, + { name: sampleOne(alphanumGenerator) }, + { name: sampleOne(alphanumGenerator) }, + { name: sampleOne(alphanumGenerator) }, ], }); diff --git a/tests/api-tests/relationships/crud/one-to-many-one-sided.test.ts b/tests/api-tests/relationships/crud/one-to-many-one-sided.test.ts index 61548357ac2..6aa9d13ea37 100644 --- a/tests/api-tests/relationships/crud/one-to-many-one-sided.test.ts +++ b/tests/api-tests/relationships/crud/one-to-many-one-sided.test.ts @@ -290,7 +290,7 @@ multiAdapterRunners().map(({ runner, provider }) => // Run the query to disconnect the location from company const _company = await context.lists.Company.updateOne({ id: company.id, - data: { location: { disconnect: { id: location.id } } }, + data: { location: null }, query: 'id location { id name }', }); expect(_company.id).toEqual(company.id); diff --git a/tests/api-tests/relationships/crud/one-to-one.test.ts b/tests/api-tests/relationships/crud/one-to-one.test.ts index 1bd4d4b30fa..8080c9553a0 100644 --- a/tests/api-tests/relationships/crud/one-to-one.test.ts +++ b/tests/api-tests/relationships/crud/one-to-one.test.ts @@ -814,7 +814,7 @@ multiAdapterRunners().map(({ runner, provider }) => // Run the query to disconnect the location from company const _company = await context.lists.Company.updateOne({ id: company.id, - data: { location: { disconnect: { id: location.id } } }, + data: { location: null }, query: 'id location { id name }', }); expect(_company.id).toEqual(company.id); @@ -836,7 +836,7 @@ multiAdapterRunners().map(({ runner, provider }) => // Run the query to disconnect the location from company const _location = await context.lists.Location.updateOne({ id: location.id, - data: { company: { disconnect: { id: company.id } } }, + data: { company: null }, query: 'id company { id name }', }); diff --git a/tests/api-tests/relationships/nested-mutations/create-and-connect-many.test.ts b/tests/api-tests/relationships/nested-mutations/create-and-connect-many.test.ts index 7548608dbc7..373451a3f21 100644 --- a/tests/api-tests/relationships/nested-mutations/create-and-connect-many.test.ts +++ b/tests/api-tests/relationships/nested-mutations/create-and-connect-many.test.ts @@ -89,7 +89,7 @@ multiAdapterRunners().map(({ runner, provider }) => // Sanity check that the items are actually created const allNotes = await context.lists.Note.findMany({ - where: { id_in: user.notes.map(({ id }) => id) }, + where: { id: { in: user.notes.map(({ id }) => id) } }, query: 'id content', }); @@ -130,7 +130,7 @@ multiAdapterRunners().map(({ runner, provider }) => // Sanity check that the items are actually created const allNotes = await context.lists.Note.findMany({ - where: { id_in: user.notes.map(({ id }) => id) }, + where: { id: { in: user.notes.map(({ id }) => id) } }, query: 'id content', }); @@ -220,7 +220,7 @@ multiAdapterRunners().map(({ runner, provider }) => query: ` mutation { updateUserToNotesNoRead( - id: "${createUser.id}" + where: { id: "${createUser.id}" } data: { username: "A thing", notes: { diff --git a/tests/api-tests/relationships/nested-mutations/create-many.test.ts b/tests/api-tests/relationships/nested-mutations/create-many.test.ts index dd450cadf76..15b4e26340d 100644 --- a/tests/api-tests/relationships/nested-mutations/create-many.test.ts +++ b/tests/api-tests/relationships/nested-mutations/create-many.test.ts @@ -235,7 +235,7 @@ multiAdapterRunners().map(({ runner, provider }) => query: ` mutation { updateUserToNotesNoRead( - id: "${createUser.id}" + where: { id: "${createUser.id}" } data: { username: "A thing", notes: { create: [{ content: "${noteContent}" }] } @@ -307,7 +307,7 @@ multiAdapterRunners().map(({ runner, provider }) => query: ` mutation { updateUserToNotesNoCreate( - id: "${createUserToNotesNoCreate.id}" + where: { id: "${createUserToNotesNoCreate.id}" } data: { username: "A thing", notes: { create: { content: "${noteContent}" } } diff --git a/tests/api-tests/relationships/nested-mutations/create-singular.test.ts b/tests/api-tests/relationships/nested-mutations/create-singular.test.ts index 9477b4626f0..7f46e647955 100644 --- a/tests/api-tests/relationships/nested-mutations/create-singular.test.ts +++ b/tests/api-tests/relationships/nested-mutations/create-singular.test.ts @@ -298,7 +298,7 @@ multiAdapterRunners().map(({ runner, provider }) => query: ` mutation { updateEventTo${group.name}( - id: "${eventModel.id}" + where: { id: "${eventModel.id}" } data: { title: "A thing", group: { create: { name: "${groupName}" } } diff --git a/tests/api-tests/relationships/nested-mutations/disconnect-all-many.test.ts b/tests/api-tests/relationships/nested-mutations/disconnect-all-many.test.ts index 7ebbecf3b85..9032871438a 100644 --- a/tests/api-tests/relationships/nested-mutations/disconnect-all-many.test.ts +++ b/tests/api-tests/relationships/nested-mutations/disconnect-all-many.test.ts @@ -93,7 +93,7 @@ multiAdapterRunners().map(({ runner, provider }) => }) ); - test( + test.skip( 'silently succeeds if used during create', runner(setupKeystone, async ({ context }) => { // Create an item that does the linking From bc9e105919163bc20b6adf2d8a94ff75c95de526 Mon Sep 17 00:00:00 2001 From: Tim Leslie Date: Mon, 17 May 2021 11:26:21 +1000 Subject: [PATCH 3/3] And some more fixes --- .../crud-self-ref/many-to-many-one-sided.test.ts | 6 +++--- .../crud-self-ref/one-to-many-one-sided.test.ts | 6 +++--- .../relationships/crud-self-ref/one-to-many.test.ts | 6 +++--- tests/api-tests/relationships/shared-names.test.ts | 2 +- tests/benchmarks/fixtures/query.js | 8 ++++---- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/tests/api-tests/relationships/crud-self-ref/many-to-many-one-sided.test.ts b/tests/api-tests/relationships/crud-self-ref/many-to-many-one-sided.test.ts index 60595bdd5ca..4a53a355b6a 100644 --- a/tests/api-tests/relationships/crud-self-ref/many-to-many-one-sided.test.ts +++ b/tests/api-tests/relationships/crud-self-ref/many-to-many-one-sided.test.ts @@ -12,9 +12,9 @@ const alphanumGenerator = gen.alphaNumString.notEmpty(); const createInitialData = async (context: KeystoneContext) => { const users = await context.lists.User.createMany({ data: [ - { data: { name: sampleOne(alphanumGenerator) } }, - { data: { name: sampleOne(alphanumGenerator) } }, - { data: { name: sampleOne(alphanumGenerator) } }, + { name: sampleOne(alphanumGenerator) }, + { name: sampleOne(alphanumGenerator) }, + { name: sampleOne(alphanumGenerator) }, ], }); diff --git a/tests/api-tests/relationships/crud-self-ref/one-to-many-one-sided.test.ts b/tests/api-tests/relationships/crud-self-ref/one-to-many-one-sided.test.ts index a1ec9750f80..58329daa450 100644 --- a/tests/api-tests/relationships/crud-self-ref/one-to-many-one-sided.test.ts +++ b/tests/api-tests/relationships/crud-self-ref/one-to-many-one-sided.test.ts @@ -12,9 +12,9 @@ const alphanumGenerator = gen.alphaNumString.notEmpty(); const createInitialData = async (context: KeystoneContext) => { const users = await context.lists.User.createMany({ data: [ - { data: { name: sampleOne(alphanumGenerator) } }, - { data: { name: sampleOne(alphanumGenerator) } }, - { data: { name: sampleOne(alphanumGenerator) } }, + { name: sampleOne(alphanumGenerator) }, + { name: sampleOne(alphanumGenerator) }, + { name: sampleOne(alphanumGenerator) }, ], }); diff --git a/tests/api-tests/relationships/crud-self-ref/one-to-many.test.ts b/tests/api-tests/relationships/crud-self-ref/one-to-many.test.ts index ad408ddf995..5c6062c3483 100644 --- a/tests/api-tests/relationships/crud-self-ref/one-to-many.test.ts +++ b/tests/api-tests/relationships/crud-self-ref/one-to-many.test.ts @@ -12,9 +12,9 @@ const alphanumGenerator = gen.alphaNumString.notEmpty(); const createInitialData = async (context: KeystoneContext) => { const users = await context.lists.User.createMany({ data: [ - { data: { name: sampleOne(alphanumGenerator) } }, - { data: { name: sampleOne(alphanumGenerator) } }, - { data: { name: sampleOne(alphanumGenerator) } }, + { name: sampleOne(alphanumGenerator) }, + { name: sampleOne(alphanumGenerator) }, + { name: sampleOne(alphanumGenerator) }, ], }); diff --git a/tests/api-tests/relationships/shared-names.test.ts b/tests/api-tests/relationships/shared-names.test.ts index bb1295a4670..a947dbf1a2a 100644 --- a/tests/api-tests/relationships/shared-names.test.ts +++ b/tests/api-tests/relationships/shared-names.test.ts @@ -137,7 +137,7 @@ multiAdapterRunners().map(({ runner, provider }) => runner(setupKeystone, async ({ context }) => { await createInitialData(context); const employees = await context.lists.Employee.findMany({ - where: { company: { employees: { some: { role: { name: 'RoleA' } } } } }, + where: { company: { employees: { some: { role: { name: { equals: 'RoleA' } } } } } }, query: 'id name', }); expect(employees).toHaveLength(1); diff --git a/tests/benchmarks/fixtures/query.js b/tests/benchmarks/fixtures/query.js index 0437769e587..c6d33a42502 100644 --- a/tests/benchmarks/fixtures/query.js +++ b/tests/benchmarks/fixtures/query.js @@ -60,7 +60,7 @@ range(14).forEach(i => { fn: async ({ context, provider }) => { const posts = { create: populate(M, i => ({ title: `post${i}` })) }; const users = await context.lists.User.createMany({ - data: populate(N, i => ({ data: { name: `test${i}`, posts } })), + data: populate(N, i => ({ name: `test${i}`, posts })), }); const userId = users[0].id; const query = `query getUser($userId: ID!) { User(where: { id: $userId }) { id } }`; @@ -88,7 +88,7 @@ range(k).forEach(i => { fn: async ({ context, provider }) => { const posts = { create: populate(M, i => ({ title: `post${i}` })) }; const users = await context.lists.User.createMany({ - data: populate(N, i => ({ data: { name: `test${i}`, posts } })), + data: populate(N, i => ({ name: `test${i}`, posts })), }); const userId = users[0].id; const query = `query getUser($userId: ID!) { User(where: { id: $userId }) { id } }`; @@ -115,7 +115,7 @@ range(14).forEach(i => { fn: async ({ context, provider }) => { const posts = { create: populate(M, i => ({ title: `post${i}` })) }; const users = await context.lists.User.createMany({ - data: populate(N, i => ({ data: { name: `test${i}`, posts } })), + data: populate(N, i => ({ name: `test${i}`, posts })), }); const userId = users[0].id; const query = `query getUser($userId: ID!) { User(where: { id: $userId }) { id posts { id } } }`; @@ -142,7 +142,7 @@ range(k).forEach(i => { fn: async ({ context, provider }) => { const posts = { create: populate(M, i => ({ title: `post${i}` })) }; const users = await context.lists.User.createMany({ - data: populate(N, i => ({ data: { name: `test${i}`, posts } })), + data: populate(N, i => ({ name: `test${i}`, posts })), }); const userId = users[0].id; const query = `query getUser($userId: ID!) { User(where: { id: $userId }) { id posts { id } } }`;