fix: don't stub every field when a mapper type is unresolvable#455
Open
GlebYavorski wants to merge 1 commit into
Open
fix: don't stub every field when a mapper type is unresolvable#455GlebYavorski wants to merge 1 commit into
GlebYavorski wants to merge 1 commit into
Conversation
`fixObjectTypeResolvers` ('smart' and 'fast') built a mapper's property
set from `getProperties()`, which returns `[]` for a TypeScript *error
type* (an unresolvable import, e.g. a client that hasn't been generated
yet). An error type was therefore indistinguishable from an empty
mapper, so a resolver stub was injected for every field, silently
overwriting hand-maintained resolver files with broken `Promise<void>`
stubs.
Detect the error type via `isNodeTypeUnresolved` before deriving the
property map; when the mapper is unresolvable, skip stub generation
(leaving existing resolvers untouched) and emit a warning naming the
mapper so the real problem — the unresolved import — surfaces.
Genuinely empty mappers (`type FooMapper = {}`) still stub as before.
Fixes eddeee888#446
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: 8301e93 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
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.
Summary
Fixes #446.
When a mapper aliases a type whose import cannot be resolved (a TypeScript error type — e.g. a Prisma/generated client that hasn't been generated yet, or a module not installed on a fresh checkout),
fixObjectTypeResolvers('smart'and'fast') treated the mapper as having zero fields and injected aresolver is required because … does notstub for every field of the schema type. This silently overwrites hand-maintained resolver files with stubs that returnPromise<void>and breaktsc.Root cause
getNodePropertyMapderives the mapper's properties fromnode.getType().getProperties(), which returns[]for an error type. The generator couldn't tell "mapper genuinely has no fields" apart from "mapper type could not be resolved", so every field took theif (!mapperProperty)branch and got a stub.Fix
isNodeTypeUnresolved, which detects the TypeScript error type (intrinsic type namederror). This is distinct from a realany(intrinsicName === 'any') and from an empty object type (not an intrinsic type at all), so it does not misfire on those.smartandfastpaths, when the mapper's declaration node is unresolved, skip stub generation for that mapper (leaving existing resolvers untouched) and emit alogger.warnnaming the mapper, so the real problem — the unresolved import — surfaces.type FooMapper = {}) still generate stubs as before.Tests
isNodeTypeUnresolvedcovering: unresolvable import →true; empty{}→false; explicitany→false; resolved import →false;undefinednode →false.getGraphQLObjectTypeResolversToGenerate(bothsmartandfast): an unresolvable mapper produces no stubs and warns once; a genuinely empty mapper still stubs every field and does not warn.nx test/lint/build typescript-resolver-filesall pass. Existing e2e snapshots are unaffected (behavior only changes for unresolvable mappers, which no fixture has).A changeset (
patch) is included.