File tree Expand file tree Collapse file tree 2 files changed +62
-2
lines changed Expand file tree Collapse file tree 2 files changed +62
-2
lines changed Original file line number Diff line number Diff line change 1
1
import React , { Component } from 'react'
2
- import LinkList from './LinkList '
2
+ import CreateLink from './CreateLink '
3
3
4
4
class App extends Component {
5
5
render ( ) {
6
- return < LinkList />
6
+ return < CreateLink /> ;
7
7
}
8
8
}
9
9
Original file line number Diff line number Diff line change
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 )
You can’t perform that action at this time.
0 commit comments