rescript-relay 1.0.0-beta.2 → 1.0.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -1
- package/package.json +1 -1
- package/relay-compiler-linux-x64/relay +0 -0
- package/relay-compiler-macos-arm64/relay +0 -0
- package/relay-compiler-macos-x64/relay +0 -0
- package/src/utils.js +159 -180
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# master
|
|
2
2
|
|
|
3
|
-
# 1.0.0-beta.
|
|
3
|
+
# 1.0.0-beta.3
|
|
4
4
|
|
|
5
5
|
_[Here's a commit showing a project being upgraded to this version](https://github.com/zth/rescript-relay/commit/5831c2f1f0f13eedc1cb60468c32fd32b2dc01d3)_
|
|
6
6
|
|
|
@@ -27,6 +27,11 @@ You can go ahead and remove these packages, that are no longer needed, as the co
|
|
|
27
27
|
|
|
28
28
|
## Beta fix changelog
|
|
29
29
|
|
|
30
|
+
### beta.3
|
|
31
|
+
|
|
32
|
+
- Fix issue with duplicate keys being printed in the conversion instructions.
|
|
33
|
+
- Get rid of the need of nullability conversion instructions, and infer them instead.
|
|
34
|
+
|
|
30
35
|
### beta.2
|
|
31
36
|
|
|
32
37
|
- Fix issue with recursive input objects not being converted correctly.
|
package/package.json
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/src/utils.js
CHANGED
|
@@ -24,6 +24,10 @@ function traverse(
|
|
|
24
24
|
instructionPaths,
|
|
25
25
|
addFragmentOnRoot
|
|
26
26
|
) {
|
|
27
|
+
// We lazily set up a new object for each "level", as we don't want to mutate
|
|
28
|
+
// what comes back from the Relay store, and nor do we want to create new
|
|
29
|
+
// objects unless we need to. And we only need to when we need to change
|
|
30
|
+
// something.
|
|
27
31
|
var newObj;
|
|
28
32
|
|
|
29
33
|
if (addFragmentOnRoot) {
|
|
@@ -39,187 +43,168 @@ function traverse(
|
|
|
39
43
|
var thisPath = makeNewPath(currentPath, [key]);
|
|
40
44
|
var path = getPathName(thisPath);
|
|
41
45
|
|
|
42
|
-
var instructions = instructionMap[path];
|
|
46
|
+
var instructions = instructionMap[path] || {};
|
|
43
47
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
+
if (currentObj[key] == null) {
|
|
49
|
+
newObj = getNewObj(newObj, currentObj);
|
|
50
|
+
newObj[key] = nullableValue;
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
48
53
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
newObj = getNewObj(newObj, currentObj);
|
|
53
|
-
newObj[key] = nullableValue;
|
|
54
|
-
}
|
|
55
|
-
} else {
|
|
56
|
-
var shouldConvertRootObj =
|
|
57
|
-
typeof instructions["r"] === "string" &&
|
|
58
|
-
fullInstructionMap[instructions["r"]];
|
|
54
|
+
var shouldConvertRootObj =
|
|
55
|
+
typeof instructions["r"] === "string" &&
|
|
56
|
+
fullInstructionMap[instructions["r"]];
|
|
59
57
|
|
|
60
|
-
|
|
58
|
+
var shouldAddFragmentFn = instructions["f"] === "";
|
|
61
59
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
!!converters[instructions["e"]];
|
|
60
|
+
var shouldConvertEnum =
|
|
61
|
+
typeof instructions["e"] === "string" && !!converters[instructions["e"]];
|
|
65
62
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
!!converters[instructions["c"]];
|
|
63
|
+
var shouldConvertCustomField =
|
|
64
|
+
typeof instructions["c"] === "string" && !!converters[instructions["c"]];
|
|
69
65
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
!!converters[instructions["u"]];
|
|
66
|
+
var shouldConvertUnion =
|
|
67
|
+
typeof instructions["u"] === "string" && !!converters[instructions["u"]];
|
|
73
68
|
|
|
74
|
-
|
|
69
|
+
var isTopLevelNodeField = typeof instructions["tnf"] === "string";
|
|
75
70
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
if (shouldConvertRootObj) {
|
|
87
|
-
return traverser(
|
|
88
|
-
v,
|
|
89
|
-
fullInstructionMap,
|
|
90
|
-
converters,
|
|
91
|
-
nullableValue,
|
|
92
|
-
instructions["r"]
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
if (shouldConvertEnum) {
|
|
97
|
-
return converters[instructions["e"]](v);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if (shouldConvertCustomField) {
|
|
101
|
-
return converters[instructions["c"]](v);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
if (
|
|
105
|
-
shouldConvertUnion &&
|
|
106
|
-
typeof v === "object" &&
|
|
107
|
-
typeof v.__typename === "string"
|
|
108
|
-
) {
|
|
109
|
-
isUnion = true;
|
|
110
|
-
|
|
111
|
-
var newPath = makeNewPath(currentPath, [key, v.__typename]);
|
|
112
|
-
|
|
113
|
-
var unionRootHasFragment =
|
|
114
|
-
(instructionMap[getPathName(newPath)] || {}).f === "";
|
|
115
|
-
|
|
116
|
-
var traversedValue = traverse(
|
|
117
|
-
fullInstructionMap,
|
|
118
|
-
newPath,
|
|
119
|
-
v,
|
|
120
|
-
instructionMap,
|
|
121
|
-
converters,
|
|
122
|
-
nullableValue,
|
|
123
|
-
instructionPaths,
|
|
124
|
-
unionRootHasFragment
|
|
125
|
-
);
|
|
126
|
-
|
|
127
|
-
return converters[instructions["u"]](traversedValue);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
if (shouldAddFragmentFn && typeof v === "object") {
|
|
131
|
-
var objWithFragmentFn = Object.assign({}, v);
|
|
132
|
-
objWithFragmentFn.fragmentRefs = Object.assign(
|
|
133
|
-
{},
|
|
134
|
-
objWithFragmentFn
|
|
135
|
-
);
|
|
136
|
-
return objWithFragmentFn;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
return v;
|
|
140
|
-
});
|
|
141
|
-
} else {
|
|
142
|
-
/**
|
|
143
|
-
* Handle normal values.
|
|
144
|
-
*/
|
|
145
|
-
var v = currentObj[key];
|
|
146
|
-
|
|
147
|
-
if (shouldConvertRootObj) {
|
|
148
|
-
newObj = getNewObj(newObj, currentObj);
|
|
149
|
-
newObj[key] = traverser(
|
|
150
|
-
v,
|
|
151
|
-
fullInstructionMap,
|
|
152
|
-
converters,
|
|
153
|
-
nullableValue,
|
|
154
|
-
instructions["r"]
|
|
155
|
-
);
|
|
156
|
-
}
|
|
71
|
+
/**
|
|
72
|
+
* Handle arrays
|
|
73
|
+
*/
|
|
74
|
+
if (Array.isArray(currentObj[key])) {
|
|
75
|
+
newObj = getNewObj(newObj, currentObj);
|
|
76
|
+
newObj[key] = currentObj[key].map(function (v) {
|
|
77
|
+
if (v == null) {
|
|
78
|
+
return nullableValue;
|
|
79
|
+
}
|
|
157
80
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
}
|
|
81
|
+
if (shouldConvertRootObj) {
|
|
82
|
+
return traverser(
|
|
83
|
+
v,
|
|
84
|
+
fullInstructionMap,
|
|
85
|
+
converters,
|
|
86
|
+
nullableValue,
|
|
87
|
+
instructions["r"]
|
|
88
|
+
);
|
|
89
|
+
}
|
|
168
90
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
}
|
|
91
|
+
if (shouldConvertEnum) {
|
|
92
|
+
return converters[instructions["e"]](v);
|
|
93
|
+
}
|
|
173
94
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
}
|
|
95
|
+
if (shouldConvertCustomField) {
|
|
96
|
+
return converters[instructions["c"]](v);
|
|
97
|
+
}
|
|
178
98
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
99
|
+
if (
|
|
100
|
+
shouldConvertUnion &&
|
|
101
|
+
typeof v === "object" &&
|
|
102
|
+
typeof v.__typename === "string"
|
|
103
|
+
) {
|
|
104
|
+
isUnion = true;
|
|
105
|
+
|
|
106
|
+
var newPath = makeNewPath(currentPath, [key, v.__typename]);
|
|
107
|
+
|
|
108
|
+
var unionRootHasFragment =
|
|
109
|
+
(instructionMap[getPathName(newPath)] || {}).f === "";
|
|
110
|
+
|
|
111
|
+
var traversedValue = traverse(
|
|
112
|
+
fullInstructionMap,
|
|
113
|
+
newPath,
|
|
114
|
+
v,
|
|
115
|
+
instructionMap,
|
|
116
|
+
converters,
|
|
117
|
+
nullableValue,
|
|
118
|
+
instructionPaths,
|
|
119
|
+
unionRootHasFragment
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
return converters[instructions["u"]](traversedValue);
|
|
123
|
+
}
|
|
185
124
|
|
|
186
|
-
|
|
125
|
+
if (shouldAddFragmentFn && typeof v === "object") {
|
|
126
|
+
var objWithFragmentFn = Object.assign({}, v);
|
|
127
|
+
objWithFragmentFn.fragmentRefs = Object.assign({}, objWithFragmentFn);
|
|
128
|
+
return objWithFragmentFn;
|
|
129
|
+
}
|
|
187
130
|
|
|
188
|
-
|
|
189
|
-
|
|
131
|
+
return v;
|
|
132
|
+
});
|
|
133
|
+
} else {
|
|
134
|
+
/**
|
|
135
|
+
* Handle normal values.
|
|
136
|
+
*/
|
|
137
|
+
var v = currentObj[key];
|
|
190
138
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
139
|
+
if (shouldConvertRootObj) {
|
|
140
|
+
newObj = getNewObj(newObj, currentObj);
|
|
141
|
+
newObj[key] = traverser(
|
|
142
|
+
v,
|
|
143
|
+
fullInstructionMap,
|
|
144
|
+
converters,
|
|
145
|
+
nullableValue,
|
|
146
|
+
instructions["r"]
|
|
147
|
+
);
|
|
148
|
+
}
|
|
201
149
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
150
|
+
if (isTopLevelNodeField) {
|
|
151
|
+
if (
|
|
152
|
+
v == null ||
|
|
153
|
+
!v.hasOwnProperty("__typename") ||
|
|
154
|
+
v.__typename !== instructions["tnf"]
|
|
155
|
+
) {
|
|
156
|
+
newObj = getNewObj(newObj, currentObj);
|
|
157
|
+
newObj[key] = nullableValue;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
205
160
|
|
|
206
|
-
|
|
207
|
-
|
|
161
|
+
if (shouldConvertEnum) {
|
|
162
|
+
newObj = getNewObj(newObj, currentObj);
|
|
163
|
+
newObj[key] = converters[instructions["e"]](v);
|
|
164
|
+
}
|
|
208
165
|
|
|
209
|
-
|
|
166
|
+
if (shouldConvertCustomField) {
|
|
167
|
+
newObj = getNewObj(newObj, currentObj);
|
|
168
|
+
newObj[key] = converters[instructions["c"]](v);
|
|
169
|
+
}
|
|
210
170
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
171
|
+
if (
|
|
172
|
+
shouldConvertUnion &&
|
|
173
|
+
v != null &&
|
|
174
|
+
typeof v === "object" &&
|
|
175
|
+
typeof v.__typename === "string"
|
|
176
|
+
) {
|
|
177
|
+
isUnion = true;
|
|
215
178
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
179
|
+
var newPath = makeNewPath(currentPath, [key, v.__typename]);
|
|
180
|
+
|
|
181
|
+
var unionRootHasFragment =
|
|
182
|
+
(instructionMap[getPathName(newPath)] || {}).f === "";
|
|
183
|
+
|
|
184
|
+
var traversedValue = traverse(
|
|
185
|
+
fullInstructionMap,
|
|
186
|
+
newPath,
|
|
187
|
+
v,
|
|
188
|
+
instructionMap,
|
|
189
|
+
converters,
|
|
190
|
+
nullableValue,
|
|
191
|
+
instructionPaths,
|
|
192
|
+
unionRootHasFragment
|
|
193
|
+
);
|
|
194
|
+
|
|
195
|
+
newObj = getNewObj(newObj, currentObj);
|
|
196
|
+
newObj[key] = converters[instructions["u"]](traversedValue);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
if (shouldAddFragmentFn && typeof v === "object") {
|
|
200
|
+
newObj = getNewObj(newObj, currentObj);
|
|
201
|
+
var objWithFragmentFn = Object.assign({}, v);
|
|
202
|
+
objWithFragmentFn.fragmentRefs = Object.assign({}, objWithFragmentFn);
|
|
203
|
+
newObj[key] = objWithFragmentFn;
|
|
219
204
|
}
|
|
220
205
|
}
|
|
221
206
|
|
|
222
|
-
if (
|
|
207
|
+
if (originalValue != null && !isUnion) {
|
|
223
208
|
var nextObj = (newObj && newObj[key]) || currentObj[key];
|
|
224
209
|
|
|
225
210
|
if (typeof nextObj === "object" && !Array.isArray(originalValue)) {
|
|
@@ -240,17 +225,21 @@ function traverse(
|
|
|
240
225
|
} else if (Array.isArray(originalValue)) {
|
|
241
226
|
newObj = getNewObj(newObj, currentObj);
|
|
242
227
|
newObj[key] = nextObj.map(function (o) {
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
228
|
+
if (typeof o === "object" && o != null) {
|
|
229
|
+
return traverse(
|
|
230
|
+
fullInstructionMap,
|
|
231
|
+
thisPath,
|
|
232
|
+
o,
|
|
233
|
+
instructionMap,
|
|
234
|
+
converters,
|
|
235
|
+
nullableValue,
|
|
236
|
+
instructionPaths
|
|
237
|
+
);
|
|
238
|
+
} else if (o == null) {
|
|
239
|
+
return nullableValue;
|
|
240
|
+
} else {
|
|
241
|
+
return o;
|
|
242
|
+
}
|
|
254
243
|
});
|
|
255
244
|
}
|
|
256
245
|
}
|
|
@@ -280,21 +269,11 @@ function traverser(
|
|
|
280
269
|
}
|
|
281
270
|
|
|
282
271
|
var instructionMaps = instructionMaps_ || {};
|
|
283
|
-
var instructionMap = instructionMaps[rootObjectKey || "__root"];
|
|
284
|
-
|
|
285
|
-
// No instructions
|
|
286
|
-
if (!instructionMap) {
|
|
287
|
-
return root;
|
|
288
|
-
}
|
|
272
|
+
var instructionMap = instructionMaps[rootObjectKey || "__root"] || {};
|
|
289
273
|
|
|
290
274
|
var converters = theConverters == null ? {} : theConverters;
|
|
291
275
|
var instructionPaths = Object.keys(instructionMap);
|
|
292
276
|
|
|
293
|
-
// Nothing to convert, bail early
|
|
294
|
-
if (instructionPaths.length === 0) {
|
|
295
|
-
return root;
|
|
296
|
-
}
|
|
297
|
-
|
|
298
277
|
// We'll add the fragmentRefs reference to the root if needed here.
|
|
299
278
|
var fragmentsOnRoot = (instructionMap[""] || {}).f === "";
|
|
300
279
|
var unionRootConverter = converters[(instructionMap[""] || {}).u];
|