Skip to content

Commit c9f8b0b

Browse files
author
Carlos Rufo Jimenez
committed
3.2-end-mutations
1 parent 25aed60 commit c9f8b0b

File tree

2 files changed

+62
-2
lines changed

2 files changed

+62
-2
lines changed

src/components/App.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import React, { Component } from 'react'
2-
import LinkList from './LinkList'
2+
import CreateLink from './CreateLink'
33

44
class App extends Component {
55
render() {
6-
return <LinkList />
6+
return <CreateLink />;
77
}
88
}
99

src/components/CreateLink.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import React, { Component } from 'react'
2+
import { graphql } from 'react-apollo'
3+
import gql from 'graphql-tag'
4+
5+
class CreateLink extends Component {
6+
state = {
7+
description: '',
8+
url: '',
9+
}
10+
11+
_createLink = async () => {
12+
const { description, url } = this.state
13+
await this.props.postMutation({
14+
variables: {
15+
description,
16+
url
17+
}
18+
})
19+
}
20+
21+
render() {
22+
return (
23+
<div>
24+
<div className="flex flex-column mt3">
25+
<input
26+
className="mb2"
27+
value={this.state.description}
28+
onChange={e => this.setState({ description: e.target.value })}
29+
type="text"
30+
placeholder="A description for the link"
31+
/>
32+
<input
33+
className="mb2"
34+
value={this.state.url}
35+
onChange={e => this.setState({ url: e.target.value })}
36+
type="text"
37+
placeholder="The URL for the link"
38+
/>
39+
</div>
40+
<button onClick={() => this._createLink()}>Submit</button>
41+
</div>
42+
)
43+
}
44+
}
45+
46+
// 1
47+
const POST_MUTATION = gql`
48+
# 2
49+
mutation PostMutation($description: String!, $url: String!) {
50+
post(description: $description, url: $url) {
51+
id
52+
createdAt
53+
url
54+
description
55+
}
56+
}
57+
`
58+
59+
// 3
60+
export default graphql(POST_MUTATION, { name: 'postMutation' })(CreateLink)

0 commit comments

Comments
 (0)