-
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
Support interpolation of route-conditional fragments that return an array of fragment references #896
Comments
Origin issue: http://stackoverflow.com/a/35471007/802047 |
This is the same issue too: #775 |
I have a similar use case. Can someone please elaborate on that 'route-conditional function'? Where is that 'route' parameter coming from? Thanks |
If you interpolate a function into your query: viewer: () => RelayQL`
fragment on Viewer {
${route => ...}
} That function will receive the |
@steveluscher Thanks. I guess it won't work for me. I'm using react-router so the given route seems like something that was generated by it. I actually need to choose the component based on a parameter (called 'hash' in my case), but I don't see any way to do it... |
Summary: Gave #896 a try. modifies `createNode` and `getChildren` to possibly return an array of nodes when a route conditional fragment reference returns an array. Let me know what you think, It's seems weird to have `createNode` possibly return an Array but I'm not sure how it could be done without it! [Updates to original PR from wincent: switched `var` to `let`/`const`, avoided an array allocation in `getChildren`.] Closes #915 Reviewed By: josephsavona Differential Revision: D3484897 Pulled By: wincent fbshipit-source-id: 0d101bf63e1a7e5669fc4bd9094e0d35c17c8c40
Closed by #915. |
Apologies if I'm missing something here, but with the ${route => COMPONENTS.map(c =>
c.getFragment('treasure').if(variables[`${route}Unlocked`])
)} syntax – is it the case that you must define this function inline to the fragment if you want to have access to const conditionalFragment = route => (
COMPONENTS[route.name].getFragment('treasure', variables)
); |
@taion You can define the function wherever you want, as long as you make sure that |
The problem is that |
@taion This is just like any function - if you need access to
|
Oops, massive brain fart on my part. 😑 Would it make sense for the signature for conditional fragments to in fact be:
It'd be a minor quality-of-life improvement in the case above, since it'd allow avoiding the apparently unnecessary extra function bind above. |
Presently there is a limitation in Relay that requires that any interpolation you perform in a
Relay.QL
block must evaluate to:a fragment reference
${Foo.getFragment('viewer')}
an array of fragment references
${COMPONENTS.map(c => c.getFragment('viewer'))}
a route-conditional function that returns exactly one fragment reference
${route => COMPONENTS[route].getFragment('viewer')}
The task at hand is to enable the interpolation of route-conditional functions that return an array of fragment references.
The text was updated successfully, but these errors were encountered: