Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disconnect fixes #5731

Merged
merged 3 commits into from
May 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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) },
],
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) },
],
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) },
],
});

Expand All @@ -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 }',
});
Expand All @@ -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');
Expand Down Expand Up @@ -247,7 +244,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);
Expand All @@ -268,7 +265,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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) },
],
});

Expand Down
10 changes: 5 additions & 5 deletions tests/api-tests/relationships/crud-self-ref/one-to-one.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) },
],
});

Expand Down Expand Up @@ -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 }',
});

Expand All @@ -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 }',
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions tests/api-tests/relationships/crud/one-to-one.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 }',
});

Expand All @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
});

Expand Down Expand Up @@ -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',
});

Expand Down Expand Up @@ -220,7 +220,7 @@ multiAdapterRunners().map(({ runner, provider }) =>
query: `
mutation {
updateUserToNotesNoRead(
id: "${createUser.id}"
where: { id: "${createUser.id}" }
data: {
username: "A thing",
notes: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}" }] }
Expand Down Expand Up @@ -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}" } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}" } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }',
});

Expand All @@ -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 }',
});

Expand All @@ -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 }',
});

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }',
});

Expand All @@ -90,19 +90,17 @@ 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 }',
});

expect(event).toMatchObject({ id: expect.any(String), group: null });
})
);

test(
test.skip(
'silently succeeds if no item to disconnect during update',
runner(setupKeystone, async ({ context }) => {
const FAKE_ID = '5b84f38256d3c2df59a0d9bf';
Expand All @@ -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)}`;
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/api-tests/relationships/shared-names.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions tests/benchmarks/fixtures/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 } }`;
Expand Down Expand Up @@ -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 } }`;
Expand All @@ -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 } } }`;
Expand All @@ -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 } } }`;
Expand Down