fix(@nestjs/graphql): emit clearer error when nested object type is used in mapped input#3944
Merged
kamilmysliwiec merged 1 commit intonestjs:masterfrom Apr 21, 2026
Conversation
When a class decorated with @ObjectType() is referenced by a field of an @inputType() (for example, via PartialType(A, InputType) where A has a nested ObjectType field), schema construction previously failed with a generic "Cannot determine a GraphQL input type" message. Detect this specific case and throw a message that names the offending class, explains that object types cannot be nested inside input types, and suggests defining a dedicated @inputType() class or passing InputType as the second argument to the mapped-type helper.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Checklist
PR Type
Issue
Closes #2841
What is the current behavior?
When a class decorated with
@ObjectType()is referenced (directly or transitively) by a field of an@InputType(), schema construction fails with:This is what happens for the scenario described in #2841:
PartialType(ClassA, InputType)re-decoratesClassAas an input type, but any nested@ObjectType()field ofClassAis still an object type, and the schema builder rejects it with a generic error that does not explain what actually went wrong.What is the new behavior?
The
InputTypeFactorynow detects the specific case where the referenced class is already registered as an@ObjectType()and throws a clearer, actionable error:This names the offending class, explains the root cause, and points users to both of the valid fixes (a dedicated
@InputType()class, or using the mapped-type helper's decorator override on the nested type). The original generic message is preserved for all other cases (unregistered types, scalars the builder cannot resolve, etc.).A focused unit test for
CannotDetermineInputTypeErrorcovers the new and preserved branches.Does this PR introduce a breaking change?
The public error type (
CannotDetermineInputTypeError) gains an optional third constructor argument; existing call sites and error handling are unaffected.Other information
The more invasive alternative — cascading the second-argument decorator override in
PartialType/PickType/OmitType/IntersectionTypeto nested types — would silently change the decoration of classes declared elsewhere and affect the schema globally. This PR deliberately limits the scope to an error-message improvement so users are immediately told what to do.