facebook / relay

Relay is a JavaScript framework for building data-driven React applications.
https://relay.dev
MIT License
18.41k stars 1.83k forks source link

relay does not pass props down to the component as requested #1487

Closed haradakunihiko closed 7 years ago

haradakunihiko commented 7 years ago

I use react-relay-router and created very simple app. Fetching to graphql server using relay is working correctly and I get desired response, but the component inside the container does not get that data correctly.

Here is my component.

class Home extends React.Component {
    render() {
        console.log(this.props.viewer) // {__dataID__: "Vmlld2VyOnZpZXdlcg=="}. it should have 'anonymous: true' and 'user: null'
        return (
            <div>
                {this.props.children}
            </div>
        )
    }
}

export default Relay.createContainer(Auth, {
  fragments: {
    viewer: (params) => {
        return Relay.QL`
          fragment on Viewer {
            anonymous
            user {
                name
                email
            }
          }
        `;
    },
  },
});

queries passed to router is very simple.

export default {
    viewer: () => Relay.QL`query { viewer }`,
}

then, graphql sent to the server is like this,

query ViewerQueries {
  viewer {
    id,
    ...F0
  }
}
fragment F0 on Viewer {
  anonymous,
  user {
    name,
    email,
    id
  },
  id
}

the response json is like this. the user is null because I haven't logged in yet. it's ok.

{"data": {"viewer": {"id": "Vmlld2VyOnZpZXdlcg==", "anonymous": true, "user": null}}}

as written above, the graphql request is correctly sent and also got correct response. But the component inside the container does not get the props.

What should I supposed to do here?

haradakunihiko commented 7 years ago

Sorry, it seems my environment problem. Deleting all webpack generated files and rebuild fixed this issue. Using happyhack and DllPlugin might do something, I will check into it.