File tree Expand file tree Collapse file tree 1 file changed +73
-0
lines changed
packages/normalize/test/query_fragments Expand file tree Collapse file tree 1 file changed +73
-0
lines changed Original file line number Diff line number Diff line change 1+ import 'package:test/test.dart' ;
2+ import 'package:gql/language.dart' ;
3+
4+ import 'package:normalize/normalize.dart' ;
5+
6+ void main () {
7+ group ('Fragment Variables' , () {
8+ final fragment = parseString ('''
9+ fragment authorFragment on Author {
10+ id
11+ __typename
12+ posts(first: \$ first) {
13+ id
14+ __typename
15+ }
16+ }
17+ ''' );
18+
19+ final normalizedMap = {
20+ 'Post:123' : {
21+ 'id' : 123 ,
22+ '__typename' : 'Post' ,
23+ },
24+ 'Author:1' : {
25+ 'id' : 1 ,
26+ '__typename' : 'Author' ,
27+ 'posts({"first":10})' : [
28+ {'\$ ref' : 'Post:123' }
29+ ]
30+ },
31+ };
32+
33+ final response = {
34+ '__typename' : 'Author' ,
35+ 'id' : 1 ,
36+ 'posts' : [
37+ {
38+ 'id' : 123 ,
39+ '__typename' : 'Post' ,
40+ }
41+ ],
42+ };
43+
44+ test ('Produces correct normalized object' , () {
45+ final normalizedResult = {};
46+ normalizeFragment (
47+ read: (dataId) => normalizedResult[dataId],
48+ write: (dataId, value) => normalizedResult[dataId] = value,
49+ document: fragment,
50+ data: response,
51+ idFields: {'id' : 1 },
52+ variables: {'first' : 10 },
53+ );
54+
55+ expect (
56+ normalizedResult,
57+ equals (normalizedMap),
58+ );
59+ });
60+
61+ test ('Produces correct nested data object' , () {
62+ expect (
63+ denormalizeFragment (
64+ document: fragment,
65+ read: (dataId) => normalizedMap[dataId],
66+ variables: {'first' : 10 },
67+ idFields: {'id' : 1 },
68+ ),
69+ equals (response),
70+ );
71+ });
72+ });
73+ }
You can’t perform that action at this time.
0 commit comments