@@ -7,39 +7,43 @@ const gun = Gun();
7
7
8
8
describe ( "graphqlGun" , ( ) => {
9
9
it ( "can do the basics" , async ( ) => {
10
- gun . get ( "foo " ) . put ( { bar : "baz" } ) ;
10
+ gun . get ( "gGcdtb " ) . put ( { bar : "baz" } ) ;
11
11
12
12
const { next } = graphqlGun (
13
- gql `{
14
- foo {
13
+ gql `
14
+ {
15
+ gGcdtb {
15
16
bar
16
17
}
17
- }` ,
18
+ }
19
+ ` ,
18
20
gun
19
21
) ;
20
22
await next ( ) ;
21
23
expect ( await next ( ) ) . toMatchSnapshot ( ) ;
22
24
} ) ;
23
25
24
26
it ( "lets you grab the chain at any point" , async ( ) => {
25
- gun . get ( "foo " ) . put ( { bar : "pop" } ) ;
27
+ gun . get ( "gGlygtcaap " ) . put ( { bar : "pop" } ) ;
26
28
27
29
const results = await graphqlGun (
28
- gql `{
29
- foo {
30
- bar {
31
- _chain
32
- hello
30
+ gql `
31
+ {
32
+ gGlygtcaap {
33
+ bar {
34
+ _chain
35
+ hello
36
+ }
33
37
}
34
38
}
35
- } ` ,
39
+ ` ,
36
40
gun
37
41
) ;
38
42
39
43
expect ( results ) . toMatchSnapshot ( ) ;
40
44
41
45
await new Promise ( resolve => {
42
- results . foo . bar . _chain . on (
46
+ results . gGlygtcaap . bar . _chain . on (
43
47
( value , key ) => {
44
48
expect ( key ) . toEqual ( "bar" ) ;
45
49
expect ( value ) . toEqual ( "pop" ) ;
@@ -48,69 +52,89 @@ describe("graphqlGun", () => {
48
52
{ changed : true }
49
53
) ;
50
54
51
- gun . get ( "foo" ) . get ( "bar" ) . put ( { some : "stuff" } ) ;
55
+ gun
56
+ . get ( "gGlygtcaap" )
57
+ . get ( "bar" )
58
+ . put ( { some : "stuff" } ) ;
52
59
} ) ;
53
60
} ) ;
54
61
55
62
it ( "iterates over sets" , async ( ) => {
63
+ const chain = gun . get ( "gGios" ) ;
56
64
await new Promise ( resolve => {
57
- const thing1 = gun . get ( "thing1" ) ;
65
+ const thing1 = chain . get ( "thing1" ) ;
58
66
thing1 . put ( { stuff : "b" , more : "ok" } ) ;
59
- gun . get ( "things" ) . set ( thing1 , resolve ) ;
67
+ chain . get ( "things" ) . set ( thing1 , resolve ) ;
60
68
} ) ;
61
69
await new Promise ( resolve => {
62
- const thing2 = gun . get ( "thing2" ) ;
70
+ const thing2 = chain . get ( "thing2" ) ;
63
71
thing2 . put ( { stuff : "c" , more : "ok" } ) ;
64
- gun . get ( "things" ) . set ( thing2 , resolve ) ;
72
+ chain . get ( "things" ) . set ( thing2 , resolve ) ;
65
73
} ) ;
66
74
67
75
const { next } = graphqlGun (
68
- gql `{
69
- things(type: Set) {
70
- stuff
76
+ gql `
77
+ {
78
+ gGios {
79
+ things(type: Set) {
80
+ stuff
81
+ }
82
+ }
71
83
}
72
- } ` ,
84
+ ` ,
73
85
gun
74
86
) ;
75
87
76
88
await next ( ) ;
77
89
78
- expect ( await next ( ) ) . toEqual ( { things : [ { stuff : "b" } , { stuff : "c" } ] } ) ;
90
+ expect ( await next ( ) ) . toEqual ( {
91
+ gGios : { things : [ { stuff : "b" } , { stuff : "c" } ] }
92
+ } ) ;
79
93
} ) ;
80
94
81
95
it ( "lets you subscribe to updates" , async ( ) => {
82
- const thing1 = gun . get ( "thing1" ) ;
83
- const thing2 = gun . get ( "thing2" ) ;
96
+ const chain = gun . get ( "gGlystu" ) ;
97
+ const thing1 = chain . get ( "thing1" ) ;
98
+ const thing2 = chain . get ( "thing2" ) ;
84
99
thing1 . put ( { stuff : "b" , more : "ok" } ) ;
85
100
thing2 . put ( { stuff : "c" , more : "ok" } ) ;
86
- gun . get ( "things" ) . set ( thing1 ) ;
87
- gun . get ( "things" ) . set ( thing2 ) ;
101
+ chain . get ( "things" ) . set ( thing1 ) ;
102
+ chain . get ( "things" ) . set ( thing2 ) ;
88
103
89
104
let { next } = graphqlGun (
90
- gql `{
91
- things(type: Set) {
92
- stuff @live
105
+ gql `
106
+ {
107
+ gGlystu {
108
+ things(type: Set) {
109
+ stuff @live
110
+ }
111
+ }
93
112
}
94
- } ` ,
113
+ ` ,
95
114
gun
96
115
) ;
97
116
98
- expect ( await next ( ) ) . toEqual ( { things : [ { stuff : "b" } , { stuff : "c" } ] } ) ;
117
+ expect ( await next ( ) ) . toEqual ( {
118
+ gGlystu : { things : [ { stuff : "b" } , { stuff : "c" } ] }
119
+ } ) ;
99
120
100
- gun . get ( "thing1" ) . put ( { stuff : "changed" } ) ;
121
+ chain . get ( "thing1" ) . put ( { stuff : "changed" } ) ;
101
122
102
123
expect ( await next ( ) ) . toEqual ( {
103
- things : [ { stuff : "changed" } , { stuff : "c" } ]
124
+ gGlystu : {
125
+ things : [ { stuff : "changed" } , { stuff : "c" } ]
126
+ }
104
127
} ) ;
105
128
} ) ;
106
129
107
130
it ( "supports mad nesting" , async ( ) => {
108
- const thing1 = gun . get ( "thing1" ) ;
109
- const thing2 = gun . get ( "thing2" ) ;
110
- const moreThings1 = gun . get ( "moreThing1" ) ;
111
- const moreThings2 = gun . get ( "moreThing2" ) ;
112
- const moreThings3 = gun . get ( "moreThing3" ) ;
113
- const moreThings4 = gun . get ( "moreThing4" ) ;
131
+ const chain = gun . get ( "Ggsmn" ) ;
132
+ const thing1 = chain . get ( "thing1" ) ;
133
+ const thing2 = chain . get ( "thing2" ) ;
134
+ const moreThings1 = chain . get ( "moreThing1" ) ;
135
+ const moreThings2 = chain . get ( "moreThing2" ) ;
136
+ const moreThings3 = chain . get ( "moreThing3" ) ;
137
+ const moreThings4 = chain . get ( "moreThing4" ) ;
114
138
moreThings1 . put ( { otherStuff : "one fish" } ) ;
115
139
moreThings2 . put ( { otherStuff : "two fish" } ) ;
116
140
moreThings3 . put ( { otherStuff : "red fish" } ) ;
@@ -121,19 +145,21 @@ describe("graphqlGun", () => {
121
145
thing1 . get ( "moreThings" ) . set ( moreThings2 ) ;
122
146
thing2 . get ( "moreThings" ) . set ( moreThings3 ) ;
123
147
thing2 . get ( "moreThings" ) . set ( moreThings4 ) ;
124
- gun . get ( "things" ) . set ( thing1 ) ;
125
- gun . get ( "things" ) . set ( thing2 ) ;
148
+ chain . get ( "things" ) . set ( thing1 ) ;
149
+ chain . get ( "things" ) . set ( thing2 ) ;
126
150
127
151
let { next } = graphqlGun (
128
- gql `{
129
- things(type: Set) {
130
- stuff
131
- moreThings(type: Set) {
132
- otherStuff
152
+ gql `
153
+ {
154
+ things(type: Set) {
155
+ stuff
156
+ moreThings(type: Set) {
157
+ otherStuff
158
+ }
133
159
}
134
160
}
135
- } ` ,
136
- gun
161
+ ` ,
162
+ chain
137
163
) ;
138
164
139
165
expect ( await next ( ) ) . toEqual ( {
@@ -151,12 +177,13 @@ describe("graphqlGun", () => {
151
177
} ) ;
152
178
153
179
it ( "supports mad nesting with subscriptions" , async ( ) => {
154
- const thing1 = gun . get ( "thing1" ) ;
155
- const thing2 = gun . get ( "thing2" ) ;
156
- const moreThings1 = gun . get ( "moreThing1" ) ;
157
- const moreThings2 = gun . get ( "moreThing2" ) ;
158
- const moreThings3 = gun . get ( "moreThing3" ) ;
159
- const moreThings4 = gun . get ( "moreThing4" ) ;
180
+ const chain = gun . get ( "gGsmnws" ) ;
181
+ const thing1 = chain . get ( "thing1" ) ;
182
+ const thing2 = chain . get ( "thing2" ) ;
183
+ const moreThings1 = chain . get ( "moreThing1" ) ;
184
+ const moreThings2 = chain . get ( "moreThing2" ) ;
185
+ const moreThings3 = chain . get ( "moreThing3" ) ;
186
+ const moreThings4 = chain . get ( "moreThing4" ) ;
160
187
moreThings1 . put ( { otherStuff : "one fish" } ) ;
161
188
moreThings2 . put ( { otherStuff : "two fish" } ) ;
162
189
moreThings3 . put ( { otherStuff : "red fish" } ) ;
@@ -167,19 +194,21 @@ describe("graphqlGun", () => {
167
194
thing1 . get ( "moreThings" ) . set ( moreThings2 ) ;
168
195
thing2 . get ( "moreThings" ) . set ( moreThings3 ) ;
169
196
thing2 . get ( "moreThings" ) . set ( moreThings4 ) ;
170
- gun . get ( "things" ) . set ( thing1 ) ;
171
- gun . get ( "things" ) . set ( thing2 ) ;
197
+ chain . get ( "things" ) . set ( thing1 ) ;
198
+ chain . get ( "things" ) . set ( thing2 ) ;
172
199
173
200
let { next } = graphqlGun (
174
- gql `{
175
- things(type: Set) @live {
176
- stuff
177
- moreThings(type: Set) {
178
- otherStuff
201
+ gql `
202
+ {
203
+ things(type: Set) @live {
204
+ stuff
205
+ moreThings(type: Set) {
206
+ otherStuff
207
+ }
179
208
}
180
209
}
181
- } ` ,
182
- gun
210
+ ` ,
211
+ chain
183
212
) ;
184
213
185
214
expect ( await next ( ) ) . toEqual ( {
@@ -195,10 +224,13 @@ describe("graphqlGun", () => {
195
224
]
196
225
} ) ;
197
226
198
- const thing3 = gun . get ( "thing3" ) ;
227
+ const thing3 = chain . get ( "thing3" ) ;
199
228
thing3 . put ( { stuff : "d" , more : "just added" } ) ;
200
229
thing2 . put ( { stuff : "cc" } ) ;
201
- gun . get ( "things" ) . set ( thing3 ) ;
230
+ chain . get ( "things" ) . set ( thing3 ) ;
231
+ const thing4 = chain . get ( "thing4" ) ;
232
+ thing4 . put ( { stuff : "e" } ) ;
233
+ chain . get ( "things" ) . set ( thing4 ) ;
202
234
203
235
expect ( await next ( ) ) . toEqual ( {
204
236
things : [
@@ -220,36 +252,34 @@ describe("graphqlGun", () => {
220
252
}
221
253
]
222
254
} ) ;
223
-
224
- const thing4 = gun . get ( "thing4" ) ;
225
- thing4 . put ( { stuff : "e" } ) ;
226
- gun . get ( "things" ) . set ( thing4 ) ;
227
255
} ) ;
228
256
229
257
it ( "works with a simple case of two properties and a promise interface" , async ( ) => {
230
258
const thing = gun . get ( "thing" ) ;
231
259
const fish = thing . get ( "fish" ) ;
232
- fish . put ( { " color" : "red" , " fins" : 2 } ) ;
260
+ fish . put ( { color : "red" , fins : 2 } ) ;
233
261
234
262
const result = await graphqlGun (
235
- gql `{
236
- thing {
237
- fish {
238
- color
239
- fins
263
+ gql `
264
+ {
265
+ thing {
266
+ fish {
267
+ color
268
+ fins
269
+ }
240
270
}
241
271
}
242
- } ` ,
272
+ ` ,
243
273
gun
244
274
) ;
245
275
246
276
expect ( result ) . toEqual ( {
247
277
thing : {
248
278
fish : {
249
- color : ' red' ,
279
+ color : " red" ,
250
280
fins : 2
251
281
}
252
282
}
253
- } )
283
+ } ) ;
254
284
} ) ;
255
285
} ) ;
0 commit comments