Suppose I have a GraphQL type Echothat repeats everything I request with some decorations. On the other hand, I have a React component that is passed to it echo messagewith some type-specific decorations Echo. How to install initialVariablesfor a component Echo?
I read that setting props installs initialVariables, however this does not work. I tried componentDidMount, but this does not work either.
This Relay Playground indicates that the message is not displayed correctly.
For context
class Echo extends React.Component {
componentDidMount() {
let {relay, message} = this.props;
relay.setVariables({
message
});
}
render() {
let name = '';
if (this.props.echo) {
name = this.props.echo.name;
}
return (
<li>Message: {name}</li>
);
}
}
Echo = Relay.createContainer(Echo, {
initialVariables: {
message: null
},
fragments: {
echo: () => Relay.QL`
fragment on Echo {
name(message: $message)
}
`,
},
});
This is the type that resolves with an echo.
let EchoType = new GraphQLObjectType({
name: 'Echo',
fields: () => ({
name: {
type: GraphQLString,
args: {
message: {
type: GraphQLString
}
},
resolve: (echo, {message}) => `Hello, ${message}!`
}
})
});
PSWai