My use case is that I have a Node application that consumes data from a CMS, and in this CMS I give users the option to select the React component as βLayoutβ. I would like Relay to be able to get a GraphQL fragment from this dynamically selected component. When the parent Layout component is mounted, it fulfills its request and receives the layout component that it needs and sets the Relay variable - then it needs to get a fragment from this component. Is there any way to do this?
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 requests and receives the layout field. When it is mounted, it sets the Component Component variable as a React component. Instead of "PostList.getFragment" I would really like to have a Component.getFragment component.
source share