@@ -11,8 +11,8 @@ import (
11
11
)
12
12
13
13
type Document struct {
14
- Title string
15
- Content string
14
+ Title string `json:"title"`
15
+ Content string `json:"content"`
16
16
}
17
17
18
18
var documents = []Document {
@@ -33,15 +33,9 @@ func main() {
33
33
Fields : graphql.Fields {
34
34
"title" : & graphql.Field {
35
35
Type : graphql .String ,
36
- Resolve : func (p graphql.ResolveParams ) (interface {}, error ) {
37
- return documents [0 ].Title , nil
38
- },
39
36
},
40
37
"content" : & graphql.Field {
41
38
Type : graphql .String ,
42
- Resolve : func (p graphql.ResolveParams ) (interface {}, error ) {
43
- return documents [0 ].Content , nil
44
- },
45
39
},
46
40
},
47
41
},
@@ -53,8 +47,14 @@ func main() {
53
47
Fields : graphql.Fields {
54
48
"document" : & graphql.Field {
55
49
Type : documentType ,
50
+ Args : graphql.FieldConfigArgument {
51
+ "docId" : & graphql.ArgumentConfig {
52
+ Type : graphql .Int ,
53
+ },
54
+ },
56
55
Resolve : func (p graphql.ResolveParams ) (interface {}, error ) {
57
- return 1 , nil
56
+ docID := p .Args ["docId" ].(int )
57
+ return documents [docID ], nil
58
58
},
59
59
},
60
60
},
@@ -67,8 +67,23 @@ func main() {
67
67
Fields : graphql.Fields {
68
68
"updateDocument" : & graphql.Field {
69
69
Type : documentType ,
70
+ Args : graphql.FieldConfigArgument {
71
+ "docId" : & graphql.ArgumentConfig {
72
+ Type : graphql .Int ,
73
+ },
74
+ "title" : & graphql.ArgumentConfig {
75
+ Type : graphql .String ,
76
+ },
77
+ "content" : & graphql.ArgumentConfig {
78
+ Type : graphql .String ,
79
+ },
80
+ },
70
81
Resolve : func (p graphql.ResolveParams ) (interface {}, error ) {
71
82
83
+ docID := p .Args ["docId" ].(int )
84
+ documents [docID ].Title = p .Args ["title" ].(string )
85
+ documents [docID ].Title = p .Args ["title" ].(string )
86
+
72
87
for _ , subscriptions := range subscriptionManager .Subscriptions () {
73
88
for _ , subscription := range subscriptions {
74
89
@@ -89,7 +104,7 @@ func main() {
89
104
}
90
105
}
91
106
92
- return 1 , nil
107
+ return documents [ docID ] , nil
93
108
},
94
109
},
95
110
},
@@ -103,12 +118,13 @@ func main() {
103
118
"documentUpdates" : & graphql.Field {
104
119
Type : documentType ,
105
120
Args : graphql.FieldConfigArgument {
106
- "postId " : & graphql.ArgumentConfig {
107
- Type : graphql .String ,
121
+ "docId " : & graphql.ArgumentConfig {
122
+ Type : graphql .Int ,
108
123
},
109
124
},
110
125
Resolve : func (p graphql.ResolveParams ) (interface {}, error ) {
111
- return 1 , nil
126
+ docID := p .Args ["docId" ].(int )
127
+ return documents [docID ], nil
112
128
},
113
129
},
114
130
},
0 commit comments