Skip to content

Commit 7c9932c

Browse files
author
Carlos Rufo Jimenez
committed
3.4-end-mutations-v2.1
1 parent f863590 commit 7c9932c

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

src/components/App.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react'
22
import LinkList from './LinkList'
3+
import CreateLink from './CreateLink'
34

4-
export default () => <LinkList />
5+
export default () => <CreateLink />

src/components/CreateLink.js

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

0 commit comments

Comments
 (0)