Question: Hi can i access props in prepareVariables on a container ?

I have a recursive structure :

```
LocationList = Relay.createContainer(LocationList, {
    fragments: {
        location: () => Relay.QL`
            fragment on LocationPart {
                id, children { 
                    id, hasChildren, value,
                    ${LocationListItem.getFragment('location')} 
                }
            }
        `
    }
});
LocationListItem = Relay.createContainer(LocationListItem, {
    initialVariables: {
        expanded: false
    },
    fragments: {
        location: (variables) => Relay.QL`
            fragment on LocationPart {
                id, path, value, description, hasChildren,
                ${LocationList.getFragment('location').if(variables.expanded)}
            }
        `
    }
});

```

And on the root i expand the first level by :

```
fragment on LocationPart {
    ${LocationListItem.getFragment('location', { expanded: true })}
}

```

I want to preserve the whole state and restore it later.
The preserve state i have covered and i pass down a object-tree with state to all nodes.
So i would like to be able to do this in prepareVariables:

```
prepareVariables() {
    return { expanded: this.props.open[this.location.id] };
}

```

I tried using a contructor:

```
constructor(props) {
    super(props);
    if (props.open[props.location.id]) 
        props.relay.setVariables({ expanded: true });
}

```

but then relay complains about 
Expected prop `location` supplied to `LocationList` to be data fetch by Relay.

Is this possible ?

Answer: 
The challenge here is that the list of expanded/collapsed components is per-instance, while Relay queries are static and constructed prior to creating any components. The static query contains one `LocationListItem` per level, while the results will contain a list of items. This means that the query can't represent different `expanded` values for different list items, since the query doesn't even have multiple list items. 

This is an explicit design decision in GraphQL and Relay: queries are static so that most queries can be executed in a single round trip (more explanation [on the Relay docs](http://facebook.github.io/relay/docs/thinking-in-relay.html#fetching-data-for-a-view)). In complex cases such as this, you can either:

* To allow fetching the data in a single pass, you can change the query itself to accept the map of expanded/collapsed items as an input argument, and adjust the return type accordingly.
* If you're okay with a few extra round trips, you can continue using the same query and use `setVariables` in the `componentDidMount` lifecycle method, setting the expanded variable based on props (like you were trying to do in `prepareVariables`).
You can't - `prepareVariables` runs before the component is rendered, and props aren't available there. Instead, use variables passed in from the parent.