Skip to content

Throw on undefined root fields#632

Open
user1736 wants to merge 3 commits intomicrosoft:mainfrom
user1736:feat/throw-on-undefined-root-fields
Open

Throw on undefined root fields#632
user1736 wants to merge 3 commits intomicrosoft:mainfrom
user1736:feat/throw-on-undefined-root-fields

Conversation

@user1736
Copy link
Contributor

Introduces a change that makes execution throw if you try to run a query/mutation without definition.

Comment on lines +494 to +499
it("Executing mutation without type definitions and/or resolver should throw", async () => {
const schemaFragment = {
schemaId: "test",
definitions: { types: {} },
resolvers: {},
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a separate test case where definitions are defined, but resolvers are not. We also want to throw in this case, right? E.g. minimal schema is passed, but resolvers are lost somewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, schema parts are coupled with corresponding resolvers so with full setup enabled it's usually both that are missing. But you're right, it's better to address it in a more robust manner.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines +567 to +569
const isRootField =
parentTypeName === "Mutation" || parentTypeName === "Query";
const unknownFieldErrorMessage = `${parentTypeName}.${fieldName} is not defined`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be probably handled inside resolveAndCompleteField instead. The test I requested will likely pass without an error with current implementation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this part specifically doesn't fit into resolveAndCompleteField since we don't even enter there when there's no type definition.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@user1736 user1736 force-pushed the feat/throw-on-undefined-root-fields branch from 84c3974 to d8db64e Compare March 9, 2026 11:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants