Skip to content

Commit

Permalink
🚸 IMPROVE: Message when @list directive and type error in schema (#478)
Browse files Browse the repository at this point in the history
  • Loading branch information
jycouet committed Aug 25, 2022
1 parent 96913af commit 115e890
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
20 changes: 20 additions & 0 deletions src/cmd/validators/typeCheck.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,26 @@ const table: Row[] = [
`,
],
},
{
title: '@list on query on field that doesn t exist',
pass: false,
documents: [
`
query TestQuery {
user {
friends_NOT_EXISTING_FIELD @list(name: "Friends") {
id
}
}
}
`,
],
check: (e: any) => {
expect(e.message).toMatchInlineSnapshot(
'"Could not find definition of friends_NOT_EXISTING_FIELD in User"'
)
},
},
{
title: '@list with parentID on query',
pass: true,
Expand Down
3 changes: 2 additions & 1 deletion src/cmd/validators/typeCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ export default async function typeCheck(
// @ts-ignore
// look at the next entry for a list or something else that would make us
// require a parent ID
rootType = rootType?.getFields()[parent.name.value].type
// if [parent.name.value] doesnt't exist, the document is not valid and it will be catch later
rootType = rootType?.getFields()[parent.name.value]?.type
}

// if we found a pagination directive, make sure that it doesn't
Expand Down

0 comments on commit 115e890

Please sign in to comment.