Skip to content

fix: transform falsy scalars and resolve root and nested fragment aliases - #272

Merged
co-sic merged 3 commits into
mainfrom
pk/fix-falsy-scalars-and-aliases
Nov 14, 2026
Merged

co-sic merged 3 commits into
mainfrom
pk/fix-falsy-scalars-and-aliases

Conversation

@co-sic

@co-sic co-sic commented Nov 14, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes three bugs in the response transform. Each has a regression test in test/transform.test.ts, and all of them fail on the current main.

  • Falsy scalar values were not transformed. transform() skipped any falsy value, so a custom scalar with 0, false or "" came back raw. For example, prices: [0, 5] returned [0, { cents: 5 }]. Now only null and undefined are passed through.

  • Aliased root fields threw. query { myItem: item { … } } failed with Query myItem not found. Root query and mutation fields now resolve their alias, using the shared mapping.

  • Fragment aliases depended on document order. A fragment that spreads another fragment defined later lost that fragment's aliases (Field cost not found in type Item). Fragments now resolve on first use. A fragment spread on the root type also built a broken .alias path; that is fixed too.

  • Aliases are resolved per operation. Since root fields now go through the alias map, a root alias in one operation (mutation { item: updateItem }) would otherwise rename an unaliased item in another operation. getSdkWrapper now passes the operation name, and addCustomScalars takes it as an optional third argument. Without a name, the merged map is used as before, and root fields that exist in the schema are kept as they are. This also fixes nested alias collisions between operations when the name is passed.

README: notes that union and interface selections need __typename.

Cleanup: removes the leftover eslint-disable comments and imports from graphql instead of graphql/type and graphql/index.

This is the first release through npm trusted publishing (#270).

🤖 Generated with Claude Code

…ases

- Apply custom scalar transforms to 0, false and empty strings, not only truthy values
- Resolve aliased root query and mutation fields instead of throwing
- Resolve aliases from fragments spread before their definition and from fragments spread on the root type
- Remove leftover eslint-disable comments and import from graphql directly
Root fields now resolve aliases, so with one alias map shared by all operations a root alias in one operation renamed an unaliased root field of the same name in another one. Keep an alias map per named operation, pass the operation name from getSdkWrapper, and keep root fields of the schema unchanged when no operation name is given.
@co-sic
co-sic merged commit 4070479 into main Nov 14, 2026
6 checks passed
@co-sic
co-sic deleted the pk/fix-falsy-scalars-and-aliases branch November 14, 2026 10:45
gastrobot pushed a commit that referenced this pull request Nov 14, 2026
# [2.3.0](v2.2.0...v2.3.0) (2026-11-14)

### Features

* transform falsy scalars and resolve root and nested fragment aliases ([#272](#272)) ([4070479](4070479))
@gastrobot

Copy link
Copy Markdown

🎉 This PR is included in version 2.3.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants