-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Feature: Allow dynamic variables in fragments #2816
Comments
This would be helpful, based on graphql/graphql-spec#204 (comment):
We would need an option in Relay Modern to deal with dynamic variables and even a replacement for We have a similar use case where we're requesting an image with a specific size, as it can't be passed by props as we'll have to pass them from the root QueryRenderer, they're defined as constants in fragments.
We'd like to get an avatar size multiplied by the pixel density of the current device, but even if we would like to add a dynamic variable based on the environment, we would have to drill down that variable from each root QueryRenderer and through each fragment, this is really inconvenient. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
The issue is still relevant. |
all queries are static in "relay modern", so you can't pass dynamic variables in fragments you need to pass them in a given query, a fragment can consume from global variable |
With the PaginationContainer, the variables can be passed to the fragment dynamically using the
getVariables
option in the connection configuration.A similar API would be useful for FragmentContainers, to allow components to be isolated from their parent QueryRenderers.
A use case is requesting images of a correct size. For example, a multi-purpose Image component might have the fragment:
The Image component is then used in many other places such as ProfileIcon, CoverPhoto, etc, which are each wrapped in their own FragmentContainer. Each has different size requirements (often depending on screen resolution), and some might be dynamic (i.e. based on the props passed to the component).
The only way to use dynamic variables at the moment is to pass them down from the root QueryRenderer, however this can be inconvenient in large component trees.
To allow components to be isolated from their respective QRs, variables could be set at the component level in some way similar to the way
getVariables
is used in the PaginationContainer.The text was updated successfully, but these errors were encountered: