diff --git a/.changeset/stale-foxes-joke.md b/.changeset/stale-foxes-joke.md new file mode 100644 index 000000000..6cc6e12b9 --- /dev/null +++ b/.changeset/stale-foxes-joke.md @@ -0,0 +1,5 @@ +--- +'houdini': patch +--- + +fix: check field existence before @list directive to have better error msg diff --git a/src/cmd/validators/typeCheck.test.ts b/src/cmd/validators/typeCheck.test.ts index a6167b66c..41532ee57 100755 --- a/src/cmd/validators/typeCheck.test.ts +++ b/src/cmd/validators/typeCheck.test.ts @@ -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, diff --git a/src/cmd/validators/typeCheck.ts b/src/cmd/validators/typeCheck.ts index af0055c3e..5644cbfd6 100755 --- a/src/cmd/validators/typeCheck.ts +++ b/src/cmd/validators/typeCheck.ts @@ -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