Skip to content

Commit

Permalink
Add tests for incomplete relationship data in update operations (#6499)
Browse files Browse the repository at this point in the history
  • Loading branch information
timleslie authored Sep 8, 2021
1 parent ce0428b commit 48be78d
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,36 @@ describe('non-matching filter', () => {
]);
})
);

test(
'errors on incomplete data',
runner(async ({ context }) => {
// Create an item to link against
const createUser = await context.lists.User.createOne({ data: {} });

// Create an item that does the linking
const { data, errors } = await context.graphql.raw({
query: `
mutation {
updateUser(
where: { id: "${createUser.id}" },
data: { notes: {} }
) {
id
}
}`,
});

expect(data).toEqual({ updateUser: null });
expectRelationshipError(errors, [
{
path: ['updateUser'],
message:
'You must provide at least one field in to-many relationship inputs but none were provided at User.notes<Note>',
},
]);
})
);
});

describe('with access control', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,34 @@ describe('non-matching filter', () => {
]);
})
);

test(
'errors on incomplete data',
runner(async ({ context }) => {
// Create an item to link against
const createEvent = await context.lists.Event.createOne({ data: {} });

// Create an item that does the linking
const { data, errors } = await context.graphql.raw({
query: `
mutation {
updateEvent(
where: { id: "${createEvent.id}" },
data: { group: {} }
) {
id
}
}`,
});
expect(data).toEqual({ updateEvent: null });
expectRelationshipError(errors, [
{
path: ['updateEvent'],
message: `Nested to-one mutations must provide exactly one field if they're provided but Event.group<Group> did not`,
},
]);
})
);
});

describe('with access control', () => {
Expand Down

0 comments on commit 48be78d

Please sign in to comment.