我正在尝试使用GraphQL通过使用this.props.mutate传入参数来编辑项目。我收到以下错误... 错误:GraphQL错误:所需类型ID的变量$ id!没有提供。因此,问题在于我将错误的ID类型传递给mutate函数。任何人都知道如何将ID类型作为正确的类型传递给mutate函数?或者我可以将ID类型从字符串转换为正确的类型以作为变量传递给mutate函数吗?谢谢
我正在使用本地组件状态来保存值以预先填写表单,以防您想知道我使用本地状态的原因
import UPDATE_CHAT_MUTATIONS from '../graphql/mutations/updateChat';
class EditChat extends React.Component {
state = {
text: '',
id: ''
}
componentWillMount() {
this._onEditLoad()
}
_onEditLoad = () => {
const chat = this.props.navigation.state.params;
this.setState({ text: chat.text, id: chat._id })
}
_onChangeText = text => this.setState({ text });
_onEditPress = async () => {
const { id, text } = this.state;
await this.props.mutate({
variables: {
_id: id,
text
}
});
Keyboard.dismiss();
this.props.navigation.goBack(null);
}
答案 0 :(得分:3)
我设法让它发挥作用!我在客户端的graphql突变上犯了一个错误。以下是有效的代码!!希望这将有助于那些面临同样问题的人。干杯
import { gql } from 'react-apollo';
export default gql`
mutation updateChat($_id: ID!, $text: String!) {
updateChat(_id: $_id, text: $text) {
text
_id
updatedAt
}
}
`;