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

getConnectionNodes is not generated for Queries & non-refetchable Fragments #296

Open
radion-chernyakov opened this issue Feb 8, 2022 · 2 comments

Comments

@radion-chernyakov
Copy link

Hello there!

Are there any reasons for generating getConnectionNodes helper for refetchable fragments only?
From my point of view, it would be nice to have it for both queries and regular fragments as well:

module SomeQuery = %relay(`
  query SomeQuery {
     whateverConnection @connection(key: "SomeConnection") {
       edges {
         node {
            id
          }
        }
      }
    }
  }
`)

let data = SomeQuery.use(~variables=(), ())
let connectionNodes = SomeQuery.getConnectionNodes(data.whateverConnection)

module SomeFragment = %relay(`
  fragment SomeFragment_node on SomeNode {
    whateverConnection @connection(key: "SomeConnection") {
      edges {
        node {
          id
        }
      }
    }
  }
`)

let data = SomeFragment.use(nodeRef)
let connectionNodes = SomeFragment.getConnectionNodes(data.whateverConnection)

Right now, for queries case, I have to wrap everything in the query with refetchable fragment, and for the case of the fragment, I have to make the fragment be refetchable even if I don't need refetch for this fragment.

@radion-chernyakov
Copy link
Author

UPD: My bad, rescript-relay generates getConnectionNodes for fragments if @connection directive is presented in fragment, so only query case

@zth
Copy link
Owner

zth commented Feb 8, 2022

There's no particular reason this couldn't be implemented on queries as well, if I remember correctly. Probably quite easy to implement.

One related feature I've been pondering for a long time is generating accessors. Imagine:

fragment SomeFragment_node on SomeNode {
   some {
     fieldGoes {
        here @rescriptRelayAccessor
    }
   }
}

// Returns option of `here`
Fragment.get_some_fieldGoes_here(fragmentData)

I think this could be quite powerful, but would likely take some time to implement (and add quite a bit of complexity).

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

No branches or pull requests

2 participants