Skip to content

Commit

Permalink
Improve error message with @list directive (#483)
Browse files Browse the repository at this point in the history
* 🚸 IMPROVE: Message when @list directive and type error in schema (#478)

* ✏️ NEW: changeset
  • Loading branch information
jycouet authored Aug 25, 2022
1 parent 807a98b commit a69138a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/stale-foxes-joke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'houdini': patch
---

fix: check field existence before @list directive to have better error msg
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 a69138a

Please sign in to comment.