-
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
recursive data #246
Comments
Recursive fragments are supported so long as you explicitly specify a stopping point. The pattern for this is to create a variable that determines if the nested item should be expanded or not - default it to false, and then only "expand" the items one level deep to begin with: export default Relay.createContainer(BabushkaListItem, {
initialVariables: {
expand: false, // use `this.props.relay.setVariables({expand: true})` to expand an additional level
},
fragments: {
babushka: (variables) => Relay.QL` # note the `variables` argument here
fragment on Babushka{
name,
${BabushkaList.getFragment('babushka').if(variables.expand)} # getFragment().if(variables.foo)
}
`
}
}); The parent component of this list can then specify that the first level of items should be expanded initially: Relay.createContainer(Foo, {
fragments: {
foo: () => Relay.QL`
fragment on Foo {
${BabushkaList.getFragment('babushka', {expand: true})} #override the default value to expand a single level of the list
... |
Just what I was looking for! Thanks a lot Joesph. |
Now I'm getting the following error: Warning: RelayContainer: Expected prop `babushka` supplied to `BabushkaList` to be data fetched
by Relay. This is likely an error unless you are purposely passing in mock data that conforms to
the shape of this component's fragment. Which doesn't make a whole lot of sense to me, because the babushka being passed to the List component is obviously fetched by Relay and not mocked by me. Am I missing something? |
@Gregoor is it possible to link to a gist of the code for the parent and child component? |
Does this suffice? I can't really make sense of the error in that context. :( Thanks for getting back to me so quickly |
Commented on the gist, but since |
Out of all the words in the english language, I pick one where the singular and plural is isomorphic. Oh brain, why? Anyway thanks, didn't know about the annotations(?). Are they already documented somewhere? I changed the naming once again to something more familiar and heteromorphic. |
Hi @Gregoor @josephsavona ...,
Relay batch the queries so in the worst case scenario, if I understand, I'll have a single GraphQL Query per level and by using a condition like ${BabushkaList.getFragment('babushka') we can tweak the thing to get n levels at the same time. Thanks for clarifications. |
@grifx: Instead of a boolean you can use a number that you decrement every level of recursion. If it's |
What is the deal with ** Edit ** Posted too soon: it's a |
@dminkovsky
|
@joesavona I was wondering just that—the relationship between if/unless and понедельник, 4 января 2016 г. пользователь Joseph Savona написал:
|
@josephsavona Hey, I tried converting your example for specifying 1 level deep for relay-modern but I still get the error:
CommentContainer.js: const fragments = graphql`
fragment commentContainer_comment on Comment {
commentId
body
dateAdded
likes
dislikes
originalComment {
commentId
}
user {
userName
}
...repliesContainer
}
`; RepliesContainer.js: const fragments = graphql`
fragment repliesContainer on Comment
@argumentDefinitions(
count: { type: "Int", defaultValue: 3 }
expandReplies: { type: "Boolean"}
) {
id
replies(
first: $count
after: $cursor
) {
totalCount
items {
commentId
...commentContainer_comment @include (if: $expandReplies)
}
}
}
`; And then in my root query I pass down Do you know what I am doing wrong? I only want to include |
First off all, love idea and the great talks about it on ReactEurope. But I still get stuck quite a lot (which I should expect from a technical preview). Here is my current problem:
My data is modeled like this:
Now I want to display a Babushka list for which I have a List and a ListItem Component:
list.js
list-item.js
Naturally this leads to the stack size being exceeded. Am I doing something wrong fragment wise?
The text was updated successfully, but these errors were encountered: