Skip to content

Commit 0a0afb3

Browse files
Merge pull request #1214 from zino-hofmann/investigate-issue-1208
investigate issue #1208
2 parents 25ec2f1 + 03a9c6c commit 0a0afb3

File tree

1 file changed

+327
-0
lines changed

1 file changed

+327
-0
lines changed

packages/graphql/test/graphql_client_test.dart

Lines changed: 327 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,333 @@ void main() {
154154
equals('bar'),
155155
);
156156
});
157+
test('issue 1208', () async {
158+
final client = GraphQLClient(
159+
cache: GraphQLCache(
160+
possibleTypes: {
161+
'WalletContentBlock': {'WalletContentBlockList'},
162+
'WalletContentItem': {'WalletContentItemContentPreview'}
163+
},
164+
),
165+
link: link,
166+
);
167+
const data = {
168+
"__typename": "Query",
169+
"walletGetContent": {
170+
"__typename": "WalletGetContentPayload",
171+
"blocks": [
172+
{
173+
"__typename": "WalletContentBlockList",
174+
"id": "1",
175+
"blockType": {
176+
"__typename": "WalletContentBlockType",
177+
"id": "horizontal-scrolling-list",
178+
},
179+
"caption": "Featured",
180+
"items": [
181+
{
182+
"__typename": "WalletContentItemContentPreview",
183+
"id": "1",
184+
"caption": "Remarkable Women #4740",
185+
"imageURL":
186+
"https://lh3.googleusercontent.com/1kXncBpOzPjZAC46GDNXvW4NL0zDv1e_E6vzsTtKEAOAvb0SwbWzwljDY5hulMqRA4zQytjYjV7B-a_jYtNG6zy9dKssov9RRRLu5ss=w600",
187+
"link":
188+
"https://opensea.io/assets/ethereum/0x3e69baab7a742c83499661c5db92386b2424df11/4740"
189+
},
190+
{
191+
"__typename": "WalletContentItemContentPreview",
192+
"id": "2",
193+
"caption": "Inftspaces",
194+
"imageURL":
195+
"https://lh3.googleusercontent.com/8h6WQ4_Kxn0c6rBujSe0flZMTSKiWGWiMOSNaSTPUchakVq4TmyBOWJi4E0GU3_5b7v4jF-vIPR24uziltXMfQHgzEj3zBCkW_Tbsw=s0",
196+
"link":
197+
"https://opensea.io/assets/ethereum/0xb11288c7237765db4782dfddcc49e31bb80132b8/90"
198+
},
199+
{
200+
"__typename": "WalletContentItemContentPreview",
201+
"id": "3",
202+
"caption": "Love on Mars",
203+
"imageURL":
204+
"https://lh3.googleusercontent.com/XoOJwf3DQ6ZWMpmmLkVqfZD3AqEM3G0xQCXNur0-u5-HAHpoMHyPJQL__5H0wpJsy2cafaaCSSxI5YPjnzCZ-4ME7hnJXrgd5292nA=s0",
205+
"link":
206+
"https://opensea.io/collection/love-on-mars-by-ruben-rojas-x-omgdrops"
207+
}
208+
]
209+
},
210+
{
211+
"__typename": "WalletContentBlockList",
212+
"id": "2",
213+
"blockType": {
214+
"__typename": "WalletContentBlockType",
215+
"id": "vertical-short-list"
216+
},
217+
"caption": "New",
218+
"items": [
219+
{
220+
"__typename": "WalletContentItemContentPreview",
221+
"id": "4",
222+
"caption": "MSO LAB Genesis #844",
223+
"imageURL":
224+
"https://lh3.googleusercontent.com/FCcSKSsYaNk9-bzks7ZWIEjFPiL8xrtb8aYnO2DG0piF9Eja1AkY55Yan-KQqtpcwISdpTWNz_W0yrmmmQM2hAHNG_AIXl7E4ATG2Q=w600",
225+
"link":
226+
"https://opensea.io/assets/ethereum/0xc2ac394984f3850027dac95fe8a62e446c5fb786/844"
227+
},
228+
{
229+
"__typename": "WalletContentItemContentPreview",
230+
"id": "5",
231+
"caption": "The Outsiders Genesis",
232+
"imageURL":
233+
"https://lh3.googleusercontent.com/AM8EkaQl32uR8N1RIiJa5ogVG1gh2faX6u4a1TAa_NhsGkA2CRG0pFfMOOxcc09q2KFq5cQNljTFkDbbScWpUT70es83Di0RRWD7fjM=s0",
234+
"link":
235+
"https://opensea.io/collection/the-outsiders-genesis"
236+
},
237+
{
238+
"__typename": "WalletContentItemContentPreview",
239+
"id": "6",
240+
"caption": "Bored Ape Yacht Club #6386",
241+
"imageURL":
242+
"https://img.seadn.io/files/968a4be8ada4a55b59de561d15522b4e.png?fit=max&w=600",
243+
"link":
244+
"https://opensea.io/assets/ethereum/0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d/6386"
245+
}
246+
]
247+
}
248+
]
249+
}
250+
};
251+
final _options = QueryOptions(
252+
document: parseString(r'''
253+
query WalletGetContent($input: WalletGetContentInput!) {
254+
__typename
255+
walletGetContent(input: $input) {
256+
__typename
257+
blocks {
258+
__typename
259+
... on WalletContentBlockList {
260+
__typename
261+
id
262+
blockType {
263+
__typename
264+
id
265+
}
266+
caption
267+
items {
268+
__typename
269+
... on WalletContentItemContentPreview {
270+
__typename
271+
id
272+
caption
273+
imageURL
274+
link
275+
}
276+
}
277+
}
278+
}
279+
}
280+
}
281+
'''),
282+
variables: <String, dynamic>{
283+
'input': {'id': 'foo'},
284+
},
285+
);
286+
287+
when(
288+
link.request(any),
289+
).thenAnswer(
290+
(_) => Stream.fromIterable([
291+
Response(
292+
data: data,
293+
context: Context().withEntry(
294+
HttpLinkResponseContext(
295+
statusCode: 200,
296+
headers: {'foo': 'bar'},
297+
),
298+
),
299+
response: {},
300+
),
301+
]),
302+
);
303+
304+
final QueryResult r = await client.query(_options);
305+
expect(r.exception, isNull);
306+
expect(r.data, equals(data));
307+
});
308+
test('issue 1208, duplicate IDs', () async {
309+
final client = GraphQLClient(
310+
cache: GraphQLCache(
311+
possibleTypes: {
312+
'WalletContentBlock': {'WalletContentBlockList'},
313+
'WalletContentItem': {'WalletContentItemContentPreview'}
314+
},
315+
),
316+
link: link,
317+
);
318+
const data = {
319+
"__typename": "Query",
320+
"walletGetContent": {
321+
"__typename": "WalletGetContentPayload",
322+
"blocks": [
323+
{
324+
"__typename": "WalletContentBlockList",
325+
"id": "1",
326+
"blockType": {
327+
"__typename": "WalletContentBlockType",
328+
"id": "horizontal-scrolling-list",
329+
},
330+
"caption": "Featured",
331+
"items": [
332+
{
333+
"__typename": "WalletContentItemContentPreview",
334+
"id": "1",
335+
"caption": "Remarkable Women #4740",
336+
"imageURL":
337+
"https://lh3.googleusercontent.com/1kXncBpOzPjZAC46GDNXvW4NL0zDv1e_E6vzsTtKEAOAvb0SwbWzwljDY5hulMqRA4zQytjYjV7B-a_jYtNG6zy9dKssov9RRRLu5ss=w600",
338+
"link":
339+
"https://opensea.io/assets/ethereum/0x3e69baab7a742c83499661c5db92386b2424df11/4740"
340+
},
341+
{
342+
"__typename": "WalletContentItemContentPreview",
343+
"id": "2",
344+
"caption": "Inftspaces",
345+
"imageURL":
346+
"https://lh3.googleusercontent.com/8h6WQ4_Kxn0c6rBujSe0flZMTSKiWGWiMOSNaSTPUchakVq4TmyBOWJi4E0GU3_5b7v4jF-vIPR24uziltXMfQHgzEj3zBCkW_Tbsw=s0",
347+
"link":
348+
"https://opensea.io/assets/ethereum/0xb11288c7237765db4782dfddcc49e31bb80132b8/90"
349+
},
350+
{
351+
"__typename": "WalletContentItemContentPreview",
352+
"id": "3",
353+
"caption": "Love on Mars",
354+
"imageURL":
355+
"https://lh3.googleusercontent.com/XoOJwf3DQ6ZWMpmmLkVqfZD3AqEM3G0xQCXNur0-u5-HAHpoMHyPJQL__5H0wpJsy2cafaaCSSxI5YPjnzCZ-4ME7hnJXrgd5292nA=s0",
356+
"link":
357+
"https://opensea.io/collection/love-on-mars-by-ruben-rojas-x-omgdrops"
358+
}
359+
]
360+
},
361+
{
362+
"__typename": "WalletContentBlockList",
363+
"id": "2",
364+
"blockType": {
365+
"__typename": "WalletContentBlockType",
366+
"id": "vertical-short-list"
367+
},
368+
"caption": "New",
369+
"items": [
370+
{
371+
"__typename": "WalletContentItemContentPreview",
372+
"id": "1",
373+
"caption": "MSO LAB Genesis #844",
374+
"imageURL":
375+
"https://lh3.googleusercontent.com/FCcSKSsYaNk9-bzks7ZWIEjFPiL8xrtb8aYnO2DG0piF9Eja1AkY55Yan-KQqtpcwISdpTWNz_W0yrmmmQM2hAHNG_AIXl7E4ATG2Q=w600",
376+
"link":
377+
"https://opensea.io/assets/ethereum/0xc2ac394984f3850027dac95fe8a62e446c5fb786/844"
378+
},
379+
{
380+
"__typename": "WalletContentItemContentPreview",
381+
"id": "2",
382+
"caption": "The Outsiders Genesis",
383+
"imageURL":
384+
"https://lh3.googleusercontent.com/AM8EkaQl32uR8N1RIiJa5ogVG1gh2faX6u4a1TAa_NhsGkA2CRG0pFfMOOxcc09q2KFq5cQNljTFkDbbScWpUT70es83Di0RRWD7fjM=s0",
385+
"link":
386+
"https://opensea.io/collection/the-outsiders-genesis"
387+
},
388+
{
389+
"__typename": "WalletContentItemContentPreview",
390+
"id": "3",
391+
"caption": "Bored Ape Yacht Club #6386",
392+
"imageURL":
393+
"https://img.seadn.io/files/968a4be8ada4a55b59de561d15522b4e.png?fit=max&w=600",
394+
"link":
395+
"https://opensea.io/assets/ethereum/0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d/6386"
396+
}
397+
]
398+
}
399+
]
400+
}
401+
};
402+
final _options = QueryOptions(
403+
document: parseString(r'''
404+
query WalletGetContent($input: WalletGetContentInput!) {
405+
__typename
406+
walletGetContent(input: $input) {
407+
__typename
408+
blocks {
409+
__typename
410+
... on WalletContentBlockList {
411+
__typename
412+
id
413+
blockType {
414+
__typename
415+
id
416+
}
417+
caption
418+
items {
419+
__typename
420+
... on WalletContentItemContentPreview {
421+
__typename
422+
id
423+
caption
424+
imageURL
425+
link
426+
}
427+
}
428+
}
429+
}
430+
}
431+
}
432+
'''),
433+
variables: <String, dynamic>{
434+
'input': {'id': 'foo'},
435+
},
436+
);
437+
438+
when(
439+
link.request(any),
440+
).thenAnswer(
441+
(_) => Stream.fromIterable([
442+
Response(
443+
data: data,
444+
context: Context().withEntry(
445+
HttpLinkResponseContext(
446+
statusCode: 200,
447+
headers: {'foo': 'bar'},
448+
),
449+
),
450+
response: {},
451+
),
452+
]),
453+
);
454+
455+
final QueryResult r = await client.query(_options);
456+
expect(r.exception, isNull);
457+
expect(
458+
r.data,
459+
equals({
460+
...data,
461+
"walletGetContent": {
462+
...data["walletGetContent"] as Map<String, dynamic>,
463+
"blocks": [
464+
{
465+
...(data["walletGetContent"]
466+
as Map<String, dynamic>)["blocks"][0]
467+
as Map<String, dynamic>,
468+
"items": ((data["walletGetContent"]
469+
as Map<String, dynamic>)["blocks"][1]
470+
as Map<String, dynamic>)["items"],
471+
},
472+
{
473+
...(data["walletGetContent"]
474+
as Map<String, dynamic>)["blocks"][1]
475+
as Map<String, dynamic>,
476+
"items": ((data["walletGetContent"]
477+
as Map<String, dynamic>)["blocks"][1]
478+
as Map<String, dynamic>)["items"],
479+
}
480+
]
481+
}
482+
}));
483+
});
157484

158485
test('successful response with parser', () async {
159486
final ResultParserFn<List<String>> parserFn = (data) {

0 commit comments

Comments
 (0)