Skip to content

Fix: detecting fragment usage in maskFragments()#379

Merged
JoviDeCroock merged 3 commits into0no-co:mainfrom
takumiyoshikawa:fix/mask-fragments-colocated-check
Dec 9, 2025
Merged

Fix: detecting fragment usage in maskFragments()#379
JoviDeCroock merged 3 commits into0no-co:mainfrom
takumiyoshikawa:fix/mask-fragments-colocated-check

Conversation

@takumiyoshikawa
Copy link
Contributor

@takumiyoshikawa takumiyoshikawa commented Dec 9, 2025

Background

I have reported the following issue to the gql.tada repository.
0no-co/gql.tada#500

Summary

When using gql.tada's maskFragments() function, the colocated fragments check was incorrectly reporting fragments as
unused, even though they were being used.

This PR fixes the false positive by detecting fragment usage in maskFragments() calls.

Example

import { maskFragments } from './graphql';
// Previously: "Unused co-located fragment PokemonFields" warning
// Now: No warning (correctly detected as used)
import { Pokemon, PokemonFields } from './fragment';

const data = { id: '1', name: 'Pikachu', fleeRate: 0.1 };
const x = maskFragments([PokemonFields], data);

console.log(Pokemon);

Changes

  • Add isMaskFragmentsCall() check in ast/checks.ts
  • Add findAllMaskFragmentsCalls() helper in ast/index.ts
  • Update diagnostics.ts to detect fragments passed to maskFragments([...], data)
  • Add e2e test for maskFragments usage

Test plan

  • Added e2e test case should not warn about unused fragments when using maskFragments
  • Run pnpm test:e2e

@changeset-bot
Copy link

changeset-bot bot commented Dec 9, 2025

🦋 Changeset detected

Latest commit: 214d770

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@0no-co/graphqlsp Patch

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

if (!ts.isCallExpression(node)) return false;
if (!ts.isIdentifier(node.expression)) return false;
// Only checks function name, not whether it's from gql.tada
return node.expression.escapedText === 'maskFragments';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently, we only check whether maskFragments is being used by looking at the function name.
I’d like to improve this if there’s a better approach, but I haven’t found a good solution yet.

@takumiyoshikawa takumiyoshikawa changed the title Fix: mask fragments colocated check Fix: detecting fragment usage in maskFragments() Dec 9, 2025
Co-authored-by: Jovi De Croock <decroockjovi@gmail.com>
@takumiyoshikawa
Copy link
Contributor Author

Thank you for the review. I’ve updated the commit suggestion accordingly.

@JoviDeCroock JoviDeCroock merged commit 10b5aba into 0no-co:main Dec 9, 2025
1 check passed
@github-actions github-actions bot mentioned this pull request Dec 9, 2025
@takumiyoshikawa takumiyoshikawa deleted the fix/mask-fragments-colocated-check branch January 14, 2026 15:19
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