My use case is that I have a Node application that consumes data from a CMS, and in that CMS I give the users the ability to select a React Component as a "Layout". I'd like for Relay to be able to get a GraphQL Fragment from that dynamically select component. When the Layout's parent component mounts, it goes through its query and gets the layout component it needs and sets a Relay variable - it then needs to get a fragment from that component. Is there a way to do that?
Here is the parent level query:
export default Relay.createContainer(WordpressPage, {
initialVariables:{
Component: null,
page: null,
showPosts: false,
limit: 5
},
prepareVariables(prevVars){
return{
...prevVars,
showPosts: true
}
},
fragments: {
viewer: ({Component, showPosts, limit}) => Relay.QL`
fragment on User {
${PostList.getFragment("viewer", {limit:limit}).if(showPosts)},
page(post_name:$page){
id,
post_title,
post_type,
post_content,
thumbnail,
layout{
meta_value
}
}
}
`,
},
});
As you can see, it queries and gets a layout field. When it mounts, it sets the Relay Component variable to be a React Component. Instead of "PostList.getFragment", I'd really like to be able to do a Component.getFragment.