forked from apollographql/react-apollo-error-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCreate.js
41 lines (37 loc) · 758 Bytes
/
Create.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import React, { Component } from 'react';
import { gql, graphql } from 'react-apollo';
class Create extends Component {
create = () => {
this.props.mutate({
variables: {
id: 3,
name: 'Maggie',
}
}).then(() => {
console.log('Mutation done');
this.props.onSuccess();
}).catch((err) => {
console.error('Mutation error', err);
});
}
render() {
return (
<div>
<button onClick={() => this.create()}>Create Person</button>
</div>
);
}
}
const mutation = gql`
mutation AddPerson($id: ID!, $name: String!) {
addPerson(id: $id, name: $name) {
id
name
}
}
`;
export default graphql(mutation, {
options: {
refetchQueries: ['People'],
}
})(Create);