facebook / relay

Relay is a JavaScript framework for building data-driven React applications.
https://relay.dev
MIT License
18.41k stars 1.83k forks source link

[lsp] Find field references not always working #4578

Open alex-statsig opened 10 months ago

alex-statsig commented 10 months ago

It seems that "find field references" does not work for fields with a scalar type (or perhaps a different bug causing it to fail sometimes).

https://github.com/facebook/relay/commit/a6eb291e6919c9d584f7f7174c707eccb9773dbb seems to add support for finding field references with the relay LSP. I'm using relay-compiler v16.1.0. In my case, I have a fragment:

const fragment = graphql`
  fragment MetricReviewSection_metricReview on CustomMetricReview {
    status
    description
    id
    creator_id
    type
    reviewer {
      full_name
    }
  }
`;

If I use "Find All References" in vscode on "reviewer", it correctly finds three instances of CustomMetricReview.reviewer. However, if I try to use it on any other field (status, description, etc.), it finds references to the whole fragment "MetricReviewSection_metricReview". If I try to do "full_name", it bubbles up to finding references of "reviewer". Thus it seems to not work for scalar fields, only fields with a subselection.

This would be extremely valuable for me for codemod/migrations where we want to find all locations of a certain field being used, but the field name is a common word (ex. in our case, we want to find Metric.name, but "name" appears a ton in general in the codebase).

tobias-tengler commented 10 months ago

Does this only happen, if you make changes to your GraphQL definitions after you've started the LSP? Maybe it's related to https://github.com/facebook/relay/issues/4447

alex-statsig commented 10 months ago

Does this only happen, if you make changes to your GraphQL definitions after you've started the LSP? Maybe it's related to #4447

I've tried reloading window (which should restart LSP) and it still behaves the same. Afaict it seems fairly consistent that anything with a subselection works fine, but if it has no subselection of fields it just bubbles up.