const Profile = t.struct({
name: t.String,
city: t.String,
about: t.String,
});
const UPDATE_USER = gql`
mutation UpdateAccountForm(
$id: ID!
$name: String
$about: String
$city: String
) {
UpdateUser(id: $id, name: $name, about: $about, city: $city) {
id
}
}
`;
export default class UpdateAccountForm extends React.Component {
state = {
user: {
name: '',
about: '',
city: '',
},
};
render() {
const { user } = this.state;
return (
<Mutation mutation={UPDATE_USER}>
{(UpdateUser, { data }) => (
<View style={styles.container}>
<Image
source={require('../Images/logoBlue.jpg')}
style={{ width: 120, height: 120 }}
/>
<Form
type={Profile}
value={user}
options={options}
onChange={this.onChange}
/>
<Button
title="Submit"
type="clear"
titleStyle={{ color: '#4873a6' }}
onPress={() => this._handleSaveAccount(UpdateUser)}
containerStyle={{ marginTop: 20 }}
/>
</View>
)}
</Mutation>
);
}
componentDidMount = () => {
client
.query({
query: gql`
query getUser($id: ID!) {
User(id: $id) {
name
city
about
}
}
`,
variables: { id: this.props.loggedInUserId },
})
_handleSaveAccount = async UpdateUser => {
const { name, about, city } = this.state.user;
const id = this.props.loggedInUserId;
const { goToBookshelf } = this.props;
await UpdateUser({
variables: {
id,
name,
about,
city,
},
}).then(() => {
goToBookshelf(id);
});
};
}
有人可以帮助我们确定这里的问题吗?
它似乎正在用于一些突变和查询,有时是抛出这样的错误。我们正在使用React Expo和前端的Apollo客户端和GraphQl,Apollo客户端和Neo4J。
模式
type User {
id: ID!
uid: ID!
name: String!
username: String!
email: String!
about: String
city: String
}
你忘记了 data:{}
const UPDATE_USER = gql`
mutation UpdateAccountForm(
data:{$id: ID!, $name: String}
) {
UpdateUser(id: $id, name: $name) {
id
}
}
`;
仔细检查是否可以发送ID,因为有时会自动创建!
祝你好运!
我能看到的唯一问题是分隔符,称为逗号",
const UPDATE_USER = gql`
mutation UpdateAccountForm($id: ID!, $name: String,
$about: String,$city: String ) {
UpdateUser(id: $id, name: $name, about: $about, city: $city) {
id
}
}`;
或请检查突变中通过表格传递的突变变量类型。