Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fields are flagged as unused after .filter() #353

Open
3 tasks done
mattias800 opened this issue Aug 26, 2024 · 1 comment · May be fixed by #356
Open
3 tasks done

Fields are flagged as unused after .filter() #353

mattias800 opened this issue Aug 26, 2024 · 1 comment · May be fixed by #356

Comments

@mattias800
Copy link

mattias800 commented Aug 26, 2024

When you have a component that takes a list, and you have logic that filters the list, the fields are incorrectly flagged as unused.

Here is a code example.

export interface CabinImageCarouselProps {
  images: Array<FragmentOf<typeof cabinImageCarouselCabinImageFragment>>;
}

export const cabinImageCarouselCabinImageFragment = graphql(`
  fragment CabinImageCarousel_CabinImage on CabinImage {
    altText
    imageDimensionCode
    url
  }
`);

export const CabinImageCarousel: React.FC<CabinImageCarouselProps> = (
  props
) => {
  const images = readFragment(
    cabinImageCarouselCabinImageFragment,
    props.images
  );

  const seatImages = useMemo<Array<CarouselImage>>(() => {
    return (
      images
        .filter((i) => i.imageDimensionCode === ImageDimensionCode["300x500"])
        .map((p) => ({
          url: p.url,
          alt: p.altText,
        })) ?? []
    );
  }, [images]);

  return <ImageCarousel images={seatImages} />;
};

In this case, altText and url are flagged as unused.

image

If I remove the filter, they are no longer flagged as unused.

image

Reproduction

No response

gql.tada version

gql.tada v1.8.6

Validations

  • I can confirm that this is a bug report, and not a feature request, RFC, question, or discussion, for which GitHub Discussions should be used
  • Read the docs.
  • Follow our Code of Conduct
@kitten kitten transferred this issue from 0no-co/gql.tada Aug 26, 2024
@JoviDeCroock
Copy link
Member

JoviDeCroock commented Aug 26, 2024

I am assuming we are missing a case for chained methods over here as it correctly picks up the accessor from filter but not from map

@JoviDeCroock JoviDeCroock linked a pull request Sep 14, 2024 that will close this issue
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 a pull request may close this issue.

2 participants