@salesforce/lds-adapters-graphql 1.124.1 → 1.124.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/dist/es/es2018/graphql-service.js +2098 -2098
- package/dist/{types → es/es2018/types}/src/__mocks__/@salesforce/lds-adapters-uiapi/sfdc/graphqlAdapters.d.ts +1 -1
- package/dist/{types → es/es2018/types}/src/configuration.d.ts +9 -9
- package/dist/{types → es/es2018/types}/src/custom/connection.d.ts +17 -17
- package/dist/{types → es/es2018/types}/src/custom/record.d.ts +46 -46
- package/dist/{types → es/es2018/types}/src/main.d.ts +20 -20
- package/dist/{types → es/es2018/types}/src/sfdc.d.ts +5 -5
- package/dist/{types → es/es2018/types}/src/type/Argument.d.ts +10 -10
- package/dist/{types → es/es2018/types}/src/type/CustomField.d.ts +4 -4
- package/dist/{types → es/es2018/types}/src/type/Document.d.ts +11 -11
- package/dist/{types → es/es2018/types}/src/type/Field.d.ts +4 -4
- package/dist/{types → es/es2018/types}/src/type/ObjectField.d.ts +2 -2
- package/dist/{types → es/es2018/types}/src/type/Operation.d.ts +5 -5
- package/dist/{types → es/es2018/types}/src/type/ScalarField.d.ts +2 -2
- package/dist/{types → es/es2018/types}/src/type/Selection.d.ts +23 -23
- package/dist/{types → es/es2018/types}/src/type/Variable.d.ts +4 -4
- package/dist/{types → es/es2018/types}/src/util/adapter.d.ts +16 -16
- package/dist/{types → es/es2018/types}/src/util/ast-to-string.d.ts +7 -7
- package/dist/{types → es/es2018/types}/src/util/equal.d.ts +7 -7
- package/dist/{types → es/es2018/types}/src/util/ingest.d.ts +18 -18
- package/dist/{types → es/es2018/types}/src/util/language.d.ts +20 -20
- package/dist/{types → es/es2018/types}/src/util/merge.d.ts +1 -1
- package/dist/{types → es/es2018/types}/src/util/read.d.ts +4 -4
- package/dist/{types → es/es2018/types}/src/util/serialize.d.ts +12 -12
- package/dist/{types → es/es2018/types}/src/util/sortUsingKey.d.ts +1 -1
- package/dist/{types → es/es2018/types}/src/util/synthetic-fields.d.ts +15 -15
- package/package.json +5 -5
- package/sfdc/index.d.ts +1 -1
- package/sfdc/index.js +2112 -2112
- package/dist/umd/es2018/graphql-service.js +0 -2164
- package/dist/umd/es5/graphql-service.js +0 -2182
|
@@ -1,2182 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2022, Salesforce, Inc.,
|
|
3
|
-
* All rights reserved.
|
|
4
|
-
* For full license text, see the LICENSE.txt file
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
(function (global, factory) {
|
|
8
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@luvio/engine'), require('@salesforce/lds-default-luvio'), require('@luvio/graphql-parser'), require('@salesforce/lds-adapters-uiapi'), require('@salesforce/lds-adapters-uiapi')) :
|
|
9
|
-
typeof define === 'function' && define.amd ? define(['exports', '@luvio/engine', '@salesforce/lds-default-luvio', '@luvio/graphql-parser', '@salesforce/lds-adapters-uiapi', '@salesforce/lds-adapters-uiapi'], factory) :
|
|
10
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.graphqlService = {}, global.engine, global.ldsDefaultLuvio, global.graphqlParser, global.graphql, global.ldsAdaptersUiapi));
|
|
11
|
-
})(this, (function (exports, engine, ldsDefaultLuvio, graphqlParser, graphql, ldsAdaptersUiapi) { 'use strict';
|
|
12
|
-
|
|
13
|
-
/******************************************************************************
|
|
14
|
-
Copyright (c) Microsoft Corporation.
|
|
15
|
-
|
|
16
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
17
|
-
purpose with or without fee is hereby granted.
|
|
18
|
-
|
|
19
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
20
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
21
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
22
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
23
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
24
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
25
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
26
|
-
***************************************************************************** */
|
|
27
|
-
|
|
28
|
-
var __assign = function() {
|
|
29
|
-
__assign = Object.assign || function __assign(t) {
|
|
30
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
31
|
-
s = arguments[i];
|
|
32
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
33
|
-
}
|
|
34
|
-
return t;
|
|
35
|
-
};
|
|
36
|
-
return __assign.apply(this, arguments);
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
function __spreadArray(to, from, pack) {
|
|
40
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
41
|
-
if (ar || !(i in from)) {
|
|
42
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
43
|
-
ar[i] = from[i];
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
var isArray = Array.isArray;
|
|
50
|
-
var keys = Object.keys, freeze = Object.freeze;
|
|
51
|
-
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
52
|
-
var parse = JSON.parse, stringify = JSON.stringify;
|
|
53
|
-
|
|
54
|
-
function sortAndCopyUsingObjectKey(arr, key) {
|
|
55
|
-
return __spreadArray([], arr, true).sort(function (a, b) {
|
|
56
|
-
var aKey = a[key];
|
|
57
|
-
var bKey = b[key];
|
|
58
|
-
if (aKey < bKey) {
|
|
59
|
-
return -1;
|
|
60
|
-
}
|
|
61
|
-
if (aKey > bKey) {
|
|
62
|
-
return 1;
|
|
63
|
-
}
|
|
64
|
-
return 0;
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function untrustedIsObject(untrusted) {
|
|
69
|
-
return typeof untrusted === 'object' && untrusted !== null && isArray(untrusted) === false;
|
|
70
|
-
}
|
|
71
|
-
function deepFreeze(value) {
|
|
72
|
-
// No need to freeze primitives
|
|
73
|
-
if (typeof value !== 'object' || value === null) {
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
if (isArray(value)) {
|
|
77
|
-
for (var i = 0, len = value.length; i < len; i += 1) {
|
|
78
|
-
deepFreeze(value[i]);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
var keys$1 = keys(value);
|
|
83
|
-
for (var i = 0, len = keys$1.length; i < len; i += 1) {
|
|
84
|
-
var v = value[keys$1[i]];
|
|
85
|
-
deepFreeze(v);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
return freeze(value);
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* A deterministic JSON stringify implementation. Heavily adapted from https://github.com/epoberezkin/fast-json-stable-stringify.
|
|
92
|
-
* This is needed because insertion order for JSON.stringify(object) affects output:
|
|
93
|
-
* JSON.stringify({a: 1, b: 2})
|
|
94
|
-
* "{"a":1,"b":2}"
|
|
95
|
-
* JSON.stringify({b: 2, a: 1})
|
|
96
|
-
* "{"b":2,"a":1}"
|
|
97
|
-
* @param data Data to be JSON-stringified.
|
|
98
|
-
* @returns JSON.stringified value with consistent ordering of keys.
|
|
99
|
-
*/
|
|
100
|
-
function stableJSONStringify(node) {
|
|
101
|
-
// This is for Date values.
|
|
102
|
-
if (node && node.toJSON && typeof node.toJSON === 'function') {
|
|
103
|
-
// eslint-disable-next-line no-param-reassign
|
|
104
|
-
node = node.toJSON();
|
|
105
|
-
}
|
|
106
|
-
if (node === undefined) {
|
|
107
|
-
return '';
|
|
108
|
-
}
|
|
109
|
-
if (typeof node === 'number') {
|
|
110
|
-
return isFinite(node) ? '' + node : 'null';
|
|
111
|
-
}
|
|
112
|
-
if (typeof node !== 'object') {
|
|
113
|
-
return stringify(node);
|
|
114
|
-
}
|
|
115
|
-
var i;
|
|
116
|
-
var out;
|
|
117
|
-
if (isArray(node)) {
|
|
118
|
-
node.sort();
|
|
119
|
-
out = '[';
|
|
120
|
-
for (i = 0; i < node.length; i++) {
|
|
121
|
-
if (i) {
|
|
122
|
-
out += ',';
|
|
123
|
-
}
|
|
124
|
-
out += stableJSONStringify(node[i]) || 'null';
|
|
125
|
-
}
|
|
126
|
-
return out + ']';
|
|
127
|
-
}
|
|
128
|
-
if (node === null) {
|
|
129
|
-
return 'null';
|
|
130
|
-
}
|
|
131
|
-
var keys$1 = keys(node).sort();
|
|
132
|
-
out = '';
|
|
133
|
-
for (i = 0; i < keys$1.length; i++) {
|
|
134
|
-
var key = keys$1[i];
|
|
135
|
-
var value = stableJSONStringify(node[key]);
|
|
136
|
-
if (!value) {
|
|
137
|
-
continue;
|
|
138
|
-
}
|
|
139
|
-
if (out) {
|
|
140
|
-
out += ',';
|
|
141
|
-
}
|
|
142
|
-
out += key + ':' + value;
|
|
143
|
-
}
|
|
144
|
-
return '{' + out + '}';
|
|
145
|
-
}
|
|
146
|
-
var namespace = 'GraphQL';
|
|
147
|
-
var representationName = 'graphql';
|
|
148
|
-
|
|
149
|
-
function serialize$1(args) {
|
|
150
|
-
return serializeArgs(args, { render: false });
|
|
151
|
-
}
|
|
152
|
-
function render$1(args, variables) {
|
|
153
|
-
return serializeArgs(args, { render: true, variables: variables });
|
|
154
|
-
}
|
|
155
|
-
function serializeArgs(args, option) {
|
|
156
|
-
var sortedArgs = option.render === true ? sortAndCopyUsingObjectKey(args, 'name') : args;
|
|
157
|
-
var str = '';
|
|
158
|
-
for (var i = 0, len = sortedArgs.length; i < len; i += 1) {
|
|
159
|
-
str = "".concat(str).concat(serializeArgumentNode(sortedArgs[i], option));
|
|
160
|
-
if (len > 1 && i < len - 1) {
|
|
161
|
-
str = "".concat(str, ",");
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
return str;
|
|
165
|
-
}
|
|
166
|
-
function serializeArgumentValueNode(valueDefinition, option) {
|
|
167
|
-
var kind = valueDefinition.kind;
|
|
168
|
-
switch (kind) {
|
|
169
|
-
case 'ObjectValue':
|
|
170
|
-
return serializeAndSortObjectValueNode(valueDefinition, option);
|
|
171
|
-
case 'ListValue':
|
|
172
|
-
return serializeAndSortListValueNode(valueDefinition, option);
|
|
173
|
-
case 'Variable':
|
|
174
|
-
return serializeVariableNode$1(valueDefinition, option);
|
|
175
|
-
default:
|
|
176
|
-
return serializeValueNode(valueDefinition);
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
function serializeVariableNode$1(literalValueNode, option) {
|
|
180
|
-
if (option.render === false) {
|
|
181
|
-
return "$".concat(literalValueNode.name);
|
|
182
|
-
}
|
|
183
|
-
return "".concat(serializeVariableValue(option.variables[literalValueNode.name]));
|
|
184
|
-
}
|
|
185
|
-
function serializeVariableValue(value) {
|
|
186
|
-
return stableJSONStringify(value);
|
|
187
|
-
}
|
|
188
|
-
function serializeAndSortListValueNode(objectValueDefinition, option) {
|
|
189
|
-
var values = objectValueDefinition.values;
|
|
190
|
-
var str = [];
|
|
191
|
-
var sorted = option.render === true ? sortAndCopyUsingObjectKey(values, 'value') : values;
|
|
192
|
-
for (var i = 0, len = sorted.length; i < len; i += 1) {
|
|
193
|
-
str.push(serializeArgumentValueNode(sorted[i], option));
|
|
194
|
-
}
|
|
195
|
-
return "[".concat(str.join(','), "]");
|
|
196
|
-
}
|
|
197
|
-
function serializeAndSortObjectValueNode(objectValueDefinition, option) {
|
|
198
|
-
var fields = objectValueDefinition.fields;
|
|
199
|
-
var str = '';
|
|
200
|
-
var fieldKeys = keys(fields).sort();
|
|
201
|
-
for (var i = 0, len = fieldKeys.length; i < len; i += 1) {
|
|
202
|
-
var fieldKey = fieldKeys[i];
|
|
203
|
-
str = "".concat(str).concat(fieldKey, ":").concat(serializeArgumentValueNode(fields[fieldKey], option));
|
|
204
|
-
if (len > 1 && i < len - 1) {
|
|
205
|
-
str = "".concat(str, ",");
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
return "{".concat(str, "}");
|
|
209
|
-
}
|
|
210
|
-
function serializeArgumentNode(arg, option) {
|
|
211
|
-
var name = arg.name, value = arg.value;
|
|
212
|
-
return "".concat(name, ":").concat(serializeArgumentValueNode(value, option));
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
function render(sel, variables) {
|
|
216
|
-
return serializeField(sel, { render: true, variables: variables });
|
|
217
|
-
}
|
|
218
|
-
function serializeField(sel, option) {
|
|
219
|
-
var fieldName = sel.name;
|
|
220
|
-
if (sel.kind === 'ScalarFieldSelection') {
|
|
221
|
-
return fieldName;
|
|
222
|
-
}
|
|
223
|
-
var selectionArguments = sel.arguments;
|
|
224
|
-
if (selectionArguments === undefined || selectionArguments.length === 0) {
|
|
225
|
-
return fieldName;
|
|
226
|
-
}
|
|
227
|
-
return "".concat(fieldName, "(").concat(option.render === true
|
|
228
|
-
? render$1(selectionArguments, option.variables)
|
|
229
|
-
: serialize$1(selectionArguments), ")");
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
function readScalarFieldSelection(builder, source, fieldName, sink) {
|
|
233
|
-
var gqlData = source[fieldName];
|
|
234
|
-
if (gqlData !== undefined && gqlData !== null && gqlData.__ref !== undefined) {
|
|
235
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
236
|
-
throw new Error("Scalar requested at \"".concat(fieldName, "\" but is instead an object at \"").concat(gqlData.__ref, "\""));
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
builder.readScalar(fieldName, source, sink);
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
var CUSTOM_FIELD_NODE_TYPE = 'Record';
|
|
243
|
-
var RECORD_DEFAULT_FIELD_VALUES = ['value', 'displayValue'];
|
|
244
|
-
function collectObjectFieldSelection(data) {
|
|
245
|
-
return {
|
|
246
|
-
value: data.value,
|
|
247
|
-
displayValue: data.displayValue,
|
|
248
|
-
};
|
|
249
|
-
}
|
|
250
|
-
function childTypeIsChildRelationships(sel, _data) {
|
|
251
|
-
return sel.type === CONNECTION_NODE_TYPE;
|
|
252
|
-
}
|
|
253
|
-
function childTypeIsSpanningGqlRecord(sel, _data) {
|
|
254
|
-
return sel.type === CUSTOM_FIELD_NODE_TYPE;
|
|
255
|
-
}
|
|
256
|
-
function convertAstToTrie(ast) {
|
|
257
|
-
var selections = ast.luvioSelections === undefined ? [] : ast.luvioSelections;
|
|
258
|
-
var children = {};
|
|
259
|
-
var trie = {
|
|
260
|
-
name: ast.name,
|
|
261
|
-
children: children,
|
|
262
|
-
};
|
|
263
|
-
for (var i = 0, len = selections.length; i < len; i += 1) {
|
|
264
|
-
var sel = getLuvioFieldNodeSelection(selections[i]);
|
|
265
|
-
var selName = sel.name, kind = sel.kind;
|
|
266
|
-
switch (kind) {
|
|
267
|
-
case 'ObjectFieldSelection': {
|
|
268
|
-
children[selName] = {
|
|
269
|
-
name: selName,
|
|
270
|
-
children: {},
|
|
271
|
-
};
|
|
272
|
-
break;
|
|
273
|
-
}
|
|
274
|
-
case 'CustomFieldSelection': {
|
|
275
|
-
children[selName] = convertAstToTrie(sel);
|
|
276
|
-
break;
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
return trie;
|
|
281
|
-
}
|
|
282
|
-
function formatSpanningCustomFieldSelection(sel, data) {
|
|
283
|
-
if (data === null) {
|
|
284
|
-
return {
|
|
285
|
-
value: {
|
|
286
|
-
displayValue: null,
|
|
287
|
-
value: null,
|
|
288
|
-
},
|
|
289
|
-
trie: convertAstToTrie(sel),
|
|
290
|
-
};
|
|
291
|
-
}
|
|
292
|
-
var _a = convertToRecordRepresentation(sel, data), recordRepresentation = _a.recordRepresentation, fieldsTrie = _a.fieldsTrie;
|
|
293
|
-
return {
|
|
294
|
-
trie: fieldsTrie,
|
|
295
|
-
value: {
|
|
296
|
-
displayValue: data.DisplayValue,
|
|
297
|
-
value: recordRepresentation,
|
|
298
|
-
},
|
|
299
|
-
};
|
|
300
|
-
}
|
|
301
|
-
function convertToRecordRepresentation(ast, record) {
|
|
302
|
-
var Id = record.Id, WeakEtag = record.WeakEtag, ApiName = record.ApiName, LastModifiedById = record.LastModifiedById, LastModifiedDate = record.LastModifiedDate, SystemModstamp = record.SystemModstamp, ldsRecordTypeId = record.ldsRecordTypeId;
|
|
303
|
-
var luvioSelections = ast.luvioSelections;
|
|
304
|
-
if (luvioSelections === undefined) {
|
|
305
|
-
// eslint-disable-next-line @salesforce/lds/no-error-in-production
|
|
306
|
-
throw new Error('Undefined selections');
|
|
307
|
-
}
|
|
308
|
-
var trieChildren = {};
|
|
309
|
-
var trie = {
|
|
310
|
-
name: ApiName,
|
|
311
|
-
children: trieChildren,
|
|
312
|
-
};
|
|
313
|
-
var childRelationships = {};
|
|
314
|
-
var fieldsBag = {};
|
|
315
|
-
for (var i = 0, len = luvioSelections.length; i < len; i += 1) {
|
|
316
|
-
var sel = getLuvioFieldNodeSelection(luvioSelections[i]);
|
|
317
|
-
var fieldName = sel.name, alias = sel.alias;
|
|
318
|
-
var propertyName = alias === undefined ? fieldName : alias;
|
|
319
|
-
var data = record[propertyName];
|
|
320
|
-
switch (sel.kind) {
|
|
321
|
-
case 'ObjectFieldSelection': {
|
|
322
|
-
trieChildren[fieldName] = {
|
|
323
|
-
name: fieldName,
|
|
324
|
-
children: {},
|
|
325
|
-
};
|
|
326
|
-
fieldsBag[fieldName] = collectObjectFieldSelection(data);
|
|
327
|
-
break;
|
|
328
|
-
}
|
|
329
|
-
case 'CustomFieldSelection': {
|
|
330
|
-
if (childTypeIsSpanningGqlRecord(sel)) {
|
|
331
|
-
var _a = formatSpanningCustomFieldSelection(sel, data), value = _a.value, trie_1 = _a.trie;
|
|
332
|
-
trieChildren[fieldName] = trie_1;
|
|
333
|
-
fieldsBag[fieldName] = value;
|
|
334
|
-
}
|
|
335
|
-
else if (childTypeIsChildRelationships(sel)) {
|
|
336
|
-
childRelationships[fieldName] = {
|
|
337
|
-
ast: sel,
|
|
338
|
-
data: data,
|
|
339
|
-
};
|
|
340
|
-
}
|
|
341
|
-
break;
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
var rep = {
|
|
346
|
-
apiName: ApiName,
|
|
347
|
-
eTag: '',
|
|
348
|
-
lastModifiedById: LastModifiedById.value,
|
|
349
|
-
lastModifiedDate: LastModifiedDate.value,
|
|
350
|
-
systemModstamp: SystemModstamp.value,
|
|
351
|
-
recordTypeId: ldsRecordTypeId === null ? null : ldsRecordTypeId.value,
|
|
352
|
-
recordTypeInfo: null,
|
|
353
|
-
childRelationships: {},
|
|
354
|
-
id: Id,
|
|
355
|
-
weakEtag: WeakEtag,
|
|
356
|
-
fields: fieldsBag,
|
|
357
|
-
};
|
|
358
|
-
return {
|
|
359
|
-
recordRepresentation: rep,
|
|
360
|
-
fieldsTrie: trie,
|
|
361
|
-
childRelationships: childRelationships,
|
|
362
|
-
};
|
|
363
|
-
}
|
|
364
|
-
var defaultRecordFieldsFragmentName = 'defaultRecordFields';
|
|
365
|
-
var defaultRecordFieldsFragment = "fragment ".concat(defaultRecordFieldsFragmentName, " on Record { __typename, ApiName, WeakEtag, Id, DisplayValue, SystemModstamp { value } LastModifiedById { value } LastModifiedDate { value } ldsRecordTypeId: RecordTypeId(fallback: true) { value } }");
|
|
366
|
-
function getChildRelationshipsKey(recordKey, propertyName) {
|
|
367
|
-
return "".concat(recordKey, "__childRelationships__").concat(propertyName);
|
|
368
|
-
}
|
|
369
|
-
var createIngest$4 = function (ast, variables) {
|
|
370
|
-
return function (data, path, luvio, store, timestamp) {
|
|
371
|
-
var _a = convertToRecordRepresentation(ast, data), recordRepresentation = _a.recordRepresentation, fieldsTrie = _a.fieldsTrie, childRelationships = _a.childRelationships;
|
|
372
|
-
var ingestRecord = ldsAdaptersUiapi.createIngestRecordWithFields(fieldsTrie, {
|
|
373
|
-
name: recordRepresentation.apiName,
|
|
374
|
-
children: {},
|
|
375
|
-
});
|
|
376
|
-
var recordIngest = ingestRecord(recordRepresentation, path, luvio, store, timestamp);
|
|
377
|
-
var recordKey = recordIngest.__ref;
|
|
378
|
-
var childRelationshipKeys = Object.keys(childRelationships);
|
|
379
|
-
for (var i = 0, len = childRelationshipKeys.length; i < len; i += 1) {
|
|
380
|
-
var propertyName = childRelationshipKeys[i];
|
|
381
|
-
var childRelationship = childRelationships[propertyName];
|
|
382
|
-
var childRelationshipAst = childRelationship.ast, childRelationshipData = childRelationship.data;
|
|
383
|
-
var fullPath = getChildRelationshipsKey(recordKey, propertyName);
|
|
384
|
-
createIngest$1(childRelationshipAst, fullPath, variables)(childRelationshipData, {
|
|
385
|
-
parent: {
|
|
386
|
-
data: data,
|
|
387
|
-
key: recordKey,
|
|
388
|
-
existing: undefined,
|
|
389
|
-
},
|
|
390
|
-
fullPath: fullPath,
|
|
391
|
-
propertyName: propertyName,
|
|
392
|
-
}, luvio, store, timestamp);
|
|
393
|
-
}
|
|
394
|
-
return recordIngest;
|
|
395
|
-
};
|
|
396
|
-
};
|
|
397
|
-
var recordProperties = {
|
|
398
|
-
Id: {
|
|
399
|
-
propertyName: 'id',
|
|
400
|
-
},
|
|
401
|
-
ApiName: {
|
|
402
|
-
propertyName: 'apiName',
|
|
403
|
-
},
|
|
404
|
-
};
|
|
405
|
-
function getNonSpanningField(sel, builder, source) {
|
|
406
|
-
var sink = {};
|
|
407
|
-
var luvioSelections = sel.luvioSelections;
|
|
408
|
-
if (luvioSelections === undefined) {
|
|
409
|
-
// eslint-disable-next-line @salesforce/lds/no-error-in-production
|
|
410
|
-
throw new Error('Empty selections not supported');
|
|
411
|
-
}
|
|
412
|
-
for (var i = 0, len = luvioSelections.length; i < len; i += 1) {
|
|
413
|
-
var sel_1 = getLuvioFieldNodeSelection(luvioSelections[i]);
|
|
414
|
-
var kind = sel_1.kind;
|
|
415
|
-
var name_1 = sel_1.name;
|
|
416
|
-
builder.enterPath(name_1);
|
|
417
|
-
if (kind !== 'ScalarFieldSelection') {
|
|
418
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
419
|
-
throw new Error("Unexpected kind \"".concat(kind, "\""));
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
builder.assignScalar(name_1, sink, source[name_1]);
|
|
423
|
-
builder.exitPath();
|
|
424
|
-
}
|
|
425
|
-
return sink;
|
|
426
|
-
}
|
|
427
|
-
function getCustomSelection(luvio, selection, builder, options, variables) {
|
|
428
|
-
var type = selection.type;
|
|
429
|
-
switch (type) {
|
|
430
|
-
case 'Record':
|
|
431
|
-
return readRecordRepresentation(luvio, selection, builder, options, variables);
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
function getScalarValue(selectionName, state) {
|
|
435
|
-
if (selectionName === 'DisplayValue') {
|
|
436
|
-
var parentFieldValue = state.parentFieldValue;
|
|
437
|
-
if (parentFieldValue === undefined) {
|
|
438
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
439
|
-
throw new Error('Unable to calculate DisplayValue');
|
|
440
|
-
}
|
|
441
|
-
else {
|
|
442
|
-
return undefined;
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
return parentFieldValue.displayValue;
|
|
446
|
-
}
|
|
447
|
-
var assignment = recordProperties[selectionName];
|
|
448
|
-
if (assignment === undefined) {
|
|
449
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
450
|
-
throw new Error("Unknown assignment for ScalarFieldSelection at property \"".concat(selectionName, "\""));
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
return state.source[assignment.propertyName];
|
|
454
|
-
}
|
|
455
|
-
function assignConnectionSelection(luvio, builder, sink, sel, recordKey, propertyName, variables) {
|
|
456
|
-
var key = getChildRelationshipsKey(recordKey, propertyName);
|
|
457
|
-
var resolved = resolveKey(builder, key);
|
|
458
|
-
if (resolved === undefined) {
|
|
459
|
-
return;
|
|
460
|
-
}
|
|
461
|
-
var data = createRead$2(luvio, sel, variables)(resolved.value, builder);
|
|
462
|
-
builder.assignNonScalar(sink, propertyName, data);
|
|
463
|
-
}
|
|
464
|
-
function assignSelection(luvio, selection, builder, state, variables) {
|
|
465
|
-
var sel = getLuvioFieldNodeSelection(selection);
|
|
466
|
-
var selectionName = sel.name, kind = sel.kind, alias = sel.alias;
|
|
467
|
-
var propertyName = alias === undefined ? selectionName : alias;
|
|
468
|
-
var source = state.source, sink = state.sink;
|
|
469
|
-
var fields = source.fields;
|
|
470
|
-
builder.enterPath(selectionName);
|
|
471
|
-
switch (kind) {
|
|
472
|
-
case 'ScalarFieldSelection': {
|
|
473
|
-
builder.assignScalar(propertyName, sink, getScalarValue(selectionName, state));
|
|
474
|
-
break;
|
|
475
|
-
}
|
|
476
|
-
case 'ObjectFieldSelection': {
|
|
477
|
-
// regular field, not spanning
|
|
478
|
-
var field = propertyLookup(builder, selectionName, fields);
|
|
479
|
-
if (field.state === PropertyLookupResultState.Missing) {
|
|
480
|
-
break;
|
|
481
|
-
}
|
|
482
|
-
var resolved = resolveLink(builder, field.value);
|
|
483
|
-
if (resolved === undefined) {
|
|
484
|
-
break;
|
|
485
|
-
}
|
|
486
|
-
var data = getNonSpanningField(sel, builder, resolved.value);
|
|
487
|
-
builder.assignNonScalar(sink, propertyName, data);
|
|
488
|
-
break;
|
|
489
|
-
}
|
|
490
|
-
case 'CustomFieldSelection': {
|
|
491
|
-
if (sel.type === 'Connection') {
|
|
492
|
-
var recordKey = ldsAdaptersUiapi.keyBuilderRecord(luvio, {
|
|
493
|
-
recordId: state.source.id,
|
|
494
|
-
});
|
|
495
|
-
assignConnectionSelection(luvio, builder, sink, sel, recordKey, propertyName, variables);
|
|
496
|
-
}
|
|
497
|
-
else {
|
|
498
|
-
var field = fields[selectionName];
|
|
499
|
-
var resolvedParentFieldValue = resolveLink(builder, field);
|
|
500
|
-
if (resolvedParentFieldValue === undefined) {
|
|
501
|
-
break;
|
|
502
|
-
}
|
|
503
|
-
var spanningFieldResult = resolvedParentFieldValue.value;
|
|
504
|
-
var spanningFieldValue = spanningFieldResult.value;
|
|
505
|
-
if (spanningFieldValue === null || typeof spanningFieldValue !== 'object') {
|
|
506
|
-
sink[propertyName] = null;
|
|
507
|
-
break;
|
|
508
|
-
}
|
|
509
|
-
var resolvedSpanningRecordValue = resolveLink(builder, spanningFieldValue);
|
|
510
|
-
if (resolvedSpanningRecordValue === undefined) {
|
|
511
|
-
break;
|
|
512
|
-
}
|
|
513
|
-
var data = getCustomSelection(luvio, sel, builder, {
|
|
514
|
-
source: resolvedSpanningRecordValue.value,
|
|
515
|
-
parentFieldValue: spanningFieldResult,
|
|
516
|
-
}, variables);
|
|
517
|
-
builder.assignNonScalar(sink, propertyName, data);
|
|
518
|
-
}
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
builder.exitPath();
|
|
522
|
-
}
|
|
523
|
-
function readRecordRepresentation(luvio, ast, builder, options, variables) {
|
|
524
|
-
var luvioSelections = ast.luvioSelections;
|
|
525
|
-
if (luvioSelections === undefined) {
|
|
526
|
-
// eslint-disable-next-line @salesforce/lds/no-error-in-production
|
|
527
|
-
throw new Error('Empty selections not supported');
|
|
528
|
-
}
|
|
529
|
-
var sink = {};
|
|
530
|
-
var state = {
|
|
531
|
-
source: options.source,
|
|
532
|
-
sink: sink,
|
|
533
|
-
parentFieldValue: options.parentFieldValue,
|
|
534
|
-
};
|
|
535
|
-
for (var i = 0, len = luvioSelections.length; i < len; i += 1) {
|
|
536
|
-
assignSelection(luvio, luvioSelections[i], builder, state, variables);
|
|
537
|
-
}
|
|
538
|
-
return sink;
|
|
539
|
-
}
|
|
540
|
-
var createRead$3 = function (luvio, ast, variables) {
|
|
541
|
-
return function (data, builder) {
|
|
542
|
-
return readRecordRepresentation(luvio, ast, builder, {
|
|
543
|
-
source: data,
|
|
544
|
-
parentFieldValue: undefined,
|
|
545
|
-
}, variables);
|
|
546
|
-
};
|
|
547
|
-
};
|
|
548
|
-
|
|
549
|
-
var createIngest$3 = function (ast, variables) {
|
|
550
|
-
var type = ast.type;
|
|
551
|
-
switch (type) {
|
|
552
|
-
case CUSTOM_FIELD_NODE_TYPE:
|
|
553
|
-
return createIngest$4(ast, variables);
|
|
554
|
-
case CONNECTION_NODE_TYPE:
|
|
555
|
-
return createIngest$1(ast, keyBuilder(ast, variables), variables);
|
|
556
|
-
}
|
|
557
|
-
// eslint-disable-next-line @salesforce/lds/no-error-in-production
|
|
558
|
-
throw new Error("Unsupported type: \"".concat(type, "\""));
|
|
559
|
-
};
|
|
560
|
-
|
|
561
|
-
function merge(existing, incoming) {
|
|
562
|
-
if (existing === undefined) {
|
|
563
|
-
return incoming;
|
|
564
|
-
}
|
|
565
|
-
// Merge existing and incoming values together
|
|
566
|
-
return __assign(__assign({}, existing), incoming);
|
|
567
|
-
}
|
|
568
|
-
|
|
569
|
-
function resolveValue(ast, variables, source) {
|
|
570
|
-
var alias = ast.alias;
|
|
571
|
-
var propertyName = render(ast, variables);
|
|
572
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
573
|
-
if (alias !== undefined && alias in source) {
|
|
574
|
-
throw new Error("Invalid alias \"".concat(alias, "\" passed to \"equal\" function. All aliases need to be normalized before calling equal"));
|
|
575
|
-
}
|
|
576
|
-
}
|
|
577
|
-
return source[propertyName];
|
|
578
|
-
}
|
|
579
|
-
function linkEquals(ast, variables, existing, incoming) {
|
|
580
|
-
var value = resolveValue(ast, variables, existing);
|
|
581
|
-
if (value === undefined) {
|
|
582
|
-
return false;
|
|
583
|
-
}
|
|
584
|
-
var incomingLink = resolveValue(ast, variables, incoming);
|
|
585
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
586
|
-
if (incomingLink === undefined) {
|
|
587
|
-
throw new Error('Unexpected undefined link');
|
|
588
|
-
}
|
|
589
|
-
}
|
|
590
|
-
return value.__ref === incomingLink.__ref;
|
|
591
|
-
}
|
|
592
|
-
function scalarFieldEquals(ast, variables, existing, incoming) {
|
|
593
|
-
var name = ast.name;
|
|
594
|
-
var value = existing[name];
|
|
595
|
-
if (value === undefined) {
|
|
596
|
-
return false;
|
|
597
|
-
}
|
|
598
|
-
return value === resolveValue(ast, variables, incoming);
|
|
599
|
-
}
|
|
600
|
-
function equals(ast, variables, existing, incoming) {
|
|
601
|
-
var selections = ast.luvioSelections === undefined ? [] : ast.luvioSelections;
|
|
602
|
-
for (var i = 0, len = selections.length; i < len; i += 1) {
|
|
603
|
-
var sel = getLuvioFieldNodeSelection(selections[i]);
|
|
604
|
-
if (sel.kind === 'ScalarFieldSelection') {
|
|
605
|
-
if (scalarFieldEquals(sel, variables, existing, incoming) === false) {
|
|
606
|
-
return false;
|
|
607
|
-
}
|
|
608
|
-
}
|
|
609
|
-
else {
|
|
610
|
-
if (linkEquals(sel, variables, existing, incoming) === false) {
|
|
611
|
-
return false;
|
|
612
|
-
}
|
|
613
|
-
}
|
|
614
|
-
}
|
|
615
|
-
return true;
|
|
616
|
-
}
|
|
617
|
-
|
|
618
|
-
var DEFAULT_GRAPHQL_TTL = 30000;
|
|
619
|
-
var GRAPHQL_INGEST_VERSION = 'GRAPHQL_INGEST_VERSION_1';
|
|
620
|
-
function createIngest$2(ast, variables) {
|
|
621
|
-
if (ast.kind === 'CustomFieldSelection') {
|
|
622
|
-
return createIngest$3(ast, variables);
|
|
623
|
-
}
|
|
624
|
-
return genericCreateIngest(ast, variables);
|
|
625
|
-
}
|
|
626
|
-
function publishDataIfChanged(params) {
|
|
627
|
-
var store = params.store, key = params.key, ast = params.ast, incoming = params.incoming, luvio = params.luvio, variables = params.variables;
|
|
628
|
-
var existing = store.readEntry(key);
|
|
629
|
-
if (existing === undefined || equals(ast, variables, existing, incoming) === false) {
|
|
630
|
-
var newData = merge(existing, incoming);
|
|
631
|
-
luvio.storePublish(key, newData);
|
|
632
|
-
}
|
|
633
|
-
}
|
|
634
|
-
function genericCreateIngest(ast, variables) {
|
|
635
|
-
var selections = ast.luvioSelections === undefined ? [] : ast.luvioSelections;
|
|
636
|
-
return function (data, path, luvio, store, timestamp) {
|
|
637
|
-
var fullPath = path.fullPath;
|
|
638
|
-
for (var i = 0, len = selections.length; i < len; i += 1) {
|
|
639
|
-
var sel = getLuvioFieldNodeSelection(selections[i]);
|
|
640
|
-
if (sel.kind === 'ScalarFieldSelection') {
|
|
641
|
-
continue;
|
|
642
|
-
}
|
|
643
|
-
var fieldName = sel.name, alias = sel.alias;
|
|
644
|
-
var readPropertyName = alias === undefined ? fieldName : alias;
|
|
645
|
-
var propertyFullPath = "".concat(fullPath, "__").concat(fieldName);
|
|
646
|
-
var writePropertyName = render(sel, variables);
|
|
647
|
-
var childPath = {
|
|
648
|
-
parent: {
|
|
649
|
-
existing: null,
|
|
650
|
-
key: fullPath,
|
|
651
|
-
data: data,
|
|
652
|
-
},
|
|
653
|
-
propertyName: readPropertyName,
|
|
654
|
-
fullPath: propertyFullPath,
|
|
655
|
-
};
|
|
656
|
-
data[writePropertyName] = createIngest$2(sel, variables)(data[readPropertyName], childPath, luvio, store, timestamp);
|
|
657
|
-
if (writePropertyName !== readPropertyName && data[readPropertyName] !== undefined) {
|
|
658
|
-
delete data[readPropertyName];
|
|
659
|
-
}
|
|
660
|
-
}
|
|
661
|
-
publishDataIfChanged({
|
|
662
|
-
ast: ast,
|
|
663
|
-
luvio: luvio,
|
|
664
|
-
store: store,
|
|
665
|
-
key: fullPath,
|
|
666
|
-
variables: {},
|
|
667
|
-
incoming: data,
|
|
668
|
-
});
|
|
669
|
-
if (data && data.__typename !== undefined) {
|
|
670
|
-
luvio.publishStoreMetadata(fullPath, {
|
|
671
|
-
representationName: data.__typename,
|
|
672
|
-
namespace: namespace,
|
|
673
|
-
ttl: DEFAULT_GRAPHQL_TTL,
|
|
674
|
-
version: GRAPHQL_INGEST_VERSION,
|
|
675
|
-
});
|
|
676
|
-
}
|
|
677
|
-
return {
|
|
678
|
-
__ref: fullPath,
|
|
679
|
-
};
|
|
680
|
-
};
|
|
681
|
-
}
|
|
682
|
-
|
|
683
|
-
var CONNECTION_NODE_TYPE = 'Connection';
|
|
684
|
-
var TYPENAME_FIELD$1 = '__typename';
|
|
685
|
-
var PAGE_INFO_REQUIRED_FIELDS = ['hasNextPage', 'hasPreviousPage'];
|
|
686
|
-
var EDGE_REQUIRED_FIELDS = ['cursor'];
|
|
687
|
-
var PROPERTY_NAME_EDGES = 'edges';
|
|
688
|
-
var PROPERTY_NAME_PAGE_INFO = 'pageInfo';
|
|
689
|
-
var PROPERTY_NAME_TOTAL_COUNT = 'totalCount';
|
|
690
|
-
function keyBuilder(ast, variables) {
|
|
691
|
-
var args = ast.arguments, name = ast.name;
|
|
692
|
-
if (args === undefined) {
|
|
693
|
-
return "".concat(namespace, "::").concat(CONNECTION_NODE_TYPE, ":").concat(name, "()");
|
|
694
|
-
}
|
|
695
|
-
var serialized = render$1(args, variables);
|
|
696
|
-
return "".concat(namespace, "::").concat(CONNECTION_NODE_TYPE, ":").concat(name, "(").concat(serialized, ")");
|
|
697
|
-
}
|
|
698
|
-
function selectEdges(luvio, builder, ast, links, variables) {
|
|
699
|
-
var sink = [];
|
|
700
|
-
for (var i = 0, len = links.length; i < len; i += 1) {
|
|
701
|
-
builder.enterPath(i);
|
|
702
|
-
var link = links[i];
|
|
703
|
-
var resolved = followLink(luvio, ast, builder, link, variables);
|
|
704
|
-
builder.assignNonScalar(sink, i, resolved);
|
|
705
|
-
builder.exitPath();
|
|
706
|
-
}
|
|
707
|
-
return sink;
|
|
708
|
-
}
|
|
709
|
-
var createRead$2 = function (luvio, ast, variables) {
|
|
710
|
-
var selections = ast.luvioSelections === undefined ? [] : ast.luvioSelections;
|
|
711
|
-
return function (source, builder) {
|
|
712
|
-
var sink = {};
|
|
713
|
-
for (var i = 0, len = selections.length; i < len; i += 1) {
|
|
714
|
-
var sel = getLuvioFieldNodeSelection(selections[i]);
|
|
715
|
-
var name_1 = sel.name, kind = sel.kind;
|
|
716
|
-
if (kind === 'ScalarFieldSelection') {
|
|
717
|
-
readScalarFieldSelection(builder, source, name_1, sink);
|
|
718
|
-
continue;
|
|
719
|
-
}
|
|
720
|
-
var readPropertyName = render(sel, variables);
|
|
721
|
-
builder.enterPath(readPropertyName);
|
|
722
|
-
var edges = resolveLink(builder, source[readPropertyName]);
|
|
723
|
-
if (edges === undefined) {
|
|
724
|
-
builder.exitPath();
|
|
725
|
-
break;
|
|
726
|
-
}
|
|
727
|
-
if (readPropertyName === PROPERTY_NAME_EDGES) {
|
|
728
|
-
var data = selectEdges(luvio, builder, sel, edges.value, variables);
|
|
729
|
-
builder.assignNonScalar(sink, readPropertyName, data);
|
|
730
|
-
}
|
|
731
|
-
else {
|
|
732
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
733
|
-
throw new Error('Not supported');
|
|
734
|
-
}
|
|
735
|
-
}
|
|
736
|
-
builder.exitPath();
|
|
737
|
-
}
|
|
738
|
-
return sink;
|
|
739
|
-
};
|
|
740
|
-
};
|
|
741
|
-
function ingestConnectionProperty(sel, data, path, luvio, store, timestamp, variables) {
|
|
742
|
-
var propertyName = sel.name;
|
|
743
|
-
switch (propertyName) {
|
|
744
|
-
case PROPERTY_NAME_EDGES:
|
|
745
|
-
return ingestConnectionEdges(sel, data, path, luvio, store, timestamp, variables);
|
|
746
|
-
}
|
|
747
|
-
}
|
|
748
|
-
function ingestConnectionEdges(sel, data, path, luvio, store, timestamp, variables) {
|
|
749
|
-
var key = path.fullPath;
|
|
750
|
-
var existing = store.readEntry(key);
|
|
751
|
-
var hasChanges = existing === undefined || data.length !== existing.length;
|
|
752
|
-
for (var i = 0, len = data.length; i < len; i += 1) {
|
|
753
|
-
var incomingItem = (data[i] = createIngest$2(sel, variables)(data[i], {
|
|
754
|
-
parent: {
|
|
755
|
-
data: data,
|
|
756
|
-
existing: null,
|
|
757
|
-
key: key,
|
|
758
|
-
},
|
|
759
|
-
propertyName: i,
|
|
760
|
-
fullPath: "".concat(key, "__").concat(i),
|
|
761
|
-
}, luvio, store, timestamp));
|
|
762
|
-
var existingItem = existing !== undefined ? existing[i] : undefined;
|
|
763
|
-
if (existingItem === undefined || existingItem.__ref !== incomingItem.__ref) {
|
|
764
|
-
hasChanges = true;
|
|
765
|
-
}
|
|
766
|
-
}
|
|
767
|
-
if (hasChanges === true) {
|
|
768
|
-
luvio.storePublish(key, data);
|
|
769
|
-
}
|
|
770
|
-
luvio.publishStoreMetadata(key, {
|
|
771
|
-
representationName: CONNECTION_NODE_TYPE,
|
|
772
|
-
namespace: namespace,
|
|
773
|
-
ttl: DEFAULT_GRAPHQL_TTL,
|
|
774
|
-
version: GRAPHQL_INGEST_VERSION,
|
|
775
|
-
});
|
|
776
|
-
return {
|
|
777
|
-
__ref: key,
|
|
778
|
-
};
|
|
779
|
-
}
|
|
780
|
-
var createIngest$1 = function (ast, key, variables) {
|
|
781
|
-
var luvioSelections = ast.luvioSelections;
|
|
782
|
-
var selections = luvioSelections === undefined ? [] : luvioSelections;
|
|
783
|
-
return function (data, path, luvio, store, timestamp) {
|
|
784
|
-
for (var i = 0, len = selections.length; i < len; i += 1) {
|
|
785
|
-
var sel = getLuvioFieldNodeSelection(selections[i]);
|
|
786
|
-
var kind = sel.kind;
|
|
787
|
-
var propertyName = sel.name;
|
|
788
|
-
if (kind !== 'ObjectFieldSelection') {
|
|
789
|
-
continue;
|
|
790
|
-
}
|
|
791
|
-
data[propertyName] = ingestConnectionProperty(sel, data[propertyName], {
|
|
792
|
-
parent: {
|
|
793
|
-
existing: null,
|
|
794
|
-
key: key,
|
|
795
|
-
data: data,
|
|
796
|
-
},
|
|
797
|
-
fullPath: "".concat(key, "__").concat(propertyName),
|
|
798
|
-
propertyName: propertyName,
|
|
799
|
-
}, luvio, store, timestamp, variables);
|
|
800
|
-
}
|
|
801
|
-
publishDataIfChanged({
|
|
802
|
-
key: key,
|
|
803
|
-
luvio: luvio,
|
|
804
|
-
store: store,
|
|
805
|
-
incoming: data,
|
|
806
|
-
variables: {},
|
|
807
|
-
ast: ast,
|
|
808
|
-
});
|
|
809
|
-
var typeName = data.__typename;
|
|
810
|
-
luvio.publishStoreMetadata(key, {
|
|
811
|
-
representationName: typeName,
|
|
812
|
-
namespace: namespace,
|
|
813
|
-
ttl: DEFAULT_GRAPHQL_TTL,
|
|
814
|
-
version: GRAPHQL_INGEST_VERSION,
|
|
815
|
-
});
|
|
816
|
-
return {
|
|
817
|
-
__ref: key,
|
|
818
|
-
};
|
|
819
|
-
};
|
|
820
|
-
};
|
|
821
|
-
function serialize(def, state) {
|
|
822
|
-
var luvioSelections = def.luvioSelections, args = def.arguments;
|
|
823
|
-
if (luvioSelections === undefined) {
|
|
824
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
825
|
-
throw new Error('Connection field node must have selections');
|
|
826
|
-
}
|
|
827
|
-
return '';
|
|
828
|
-
}
|
|
829
|
-
var argsString = args === undefined || args.length === 0 ? '' : "(".concat(serializeArguments(args), ")");
|
|
830
|
-
var seenFields = {};
|
|
831
|
-
var serializedFields = [];
|
|
832
|
-
for (var i = 0; i < luvioSelections.length; i++) {
|
|
833
|
-
var sel = getLuvioFieldNodeSelection(luvioSelections[i]);
|
|
834
|
-
var fieldName = sel.name;
|
|
835
|
-
seenFields[fieldName] = true;
|
|
836
|
-
if (fieldName === PROPERTY_NAME_PAGE_INFO) {
|
|
837
|
-
serializedFields.push(serializePageInfo(sel, state));
|
|
838
|
-
}
|
|
839
|
-
else if (fieldName === PROPERTY_NAME_EDGES) {
|
|
840
|
-
serializedFields.push(serializeEdges(sel, state));
|
|
841
|
-
}
|
|
842
|
-
else {
|
|
843
|
-
serializedFields.push(serializeFieldNode(sel, state));
|
|
844
|
-
}
|
|
845
|
-
}
|
|
846
|
-
appendRequiredConnectionFields(seenFields, serializedFields);
|
|
847
|
-
return "".concat(serializeFieldNodeName(def)).concat(argsString, " { ").concat(serializedFields.join(' '), " }");
|
|
848
|
-
}
|
|
849
|
-
function serializeEdges(node, state) {
|
|
850
|
-
if (!isLuvioFieldNodeObjectFieldNode(node)) {
|
|
851
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
852
|
-
throw new Error('PageInfo must be an ObjectFieldNode');
|
|
853
|
-
}
|
|
854
|
-
return '';
|
|
855
|
-
}
|
|
856
|
-
var luvioSelections = node.luvioSelections;
|
|
857
|
-
if (luvioSelections === undefined)
|
|
858
|
-
return '';
|
|
859
|
-
var seenFields = {};
|
|
860
|
-
var serializedFields = [];
|
|
861
|
-
for (var i = 0; i < luvioSelections.length; i++) {
|
|
862
|
-
var sel = getLuvioFieldNodeSelection(luvioSelections[i]);
|
|
863
|
-
seenFields[sel.name] = true;
|
|
864
|
-
serializedFields.push(serializeFieldNode(sel, state));
|
|
865
|
-
}
|
|
866
|
-
appendRequiredFields(EDGE_REQUIRED_FIELDS, seenFields, serializedFields);
|
|
867
|
-
insertTypeName(seenFields, serializedFields);
|
|
868
|
-
return "".concat(serializeFieldNodeName(node), " { ").concat(serializedFields.join(' '), " }");
|
|
869
|
-
}
|
|
870
|
-
function serializePageInfo(node, state) {
|
|
871
|
-
if (!isLuvioFieldNodeObjectFieldNode(node)) {
|
|
872
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
873
|
-
throw new Error('PageInfo must be an ObjectFieldNode');
|
|
874
|
-
}
|
|
875
|
-
return '';
|
|
876
|
-
}
|
|
877
|
-
var luvioSelections = node.luvioSelections;
|
|
878
|
-
if (luvioSelections === undefined)
|
|
879
|
-
return '';
|
|
880
|
-
var seenFields = {};
|
|
881
|
-
var serializedFields = [];
|
|
882
|
-
for (var i = 0; i < luvioSelections.length; i++) {
|
|
883
|
-
var sel = getLuvioFieldNodeSelection(luvioSelections[i]);
|
|
884
|
-
seenFields[sel.name] = true;
|
|
885
|
-
serializedFields.push(serializeFieldNode(sel, state));
|
|
886
|
-
}
|
|
887
|
-
appendRequiredFields(PAGE_INFO_REQUIRED_FIELDS, seenFields, serializedFields);
|
|
888
|
-
return "".concat(serializeFieldNodeName(node), " { ").concat(serializedFields.join(' '), " }");
|
|
889
|
-
}
|
|
890
|
-
function appendRequiredFields(requiredFields, seenFields, result) {
|
|
891
|
-
for (var i = 0; i < requiredFields.length; i++) {
|
|
892
|
-
var fieldName = requiredFields[i];
|
|
893
|
-
if (seenFields[fieldName] !== true) {
|
|
894
|
-
result.push(fieldName);
|
|
895
|
-
}
|
|
896
|
-
}
|
|
897
|
-
}
|
|
898
|
-
function appendRequiredConnectionFields(seenFields, result) {
|
|
899
|
-
if (seenFields[PROPERTY_NAME_PAGE_INFO] !== true) {
|
|
900
|
-
result.push('pageInfo { hasNextPage hasPreviousPage }');
|
|
901
|
-
}
|
|
902
|
-
if (seenFields[PROPERTY_NAME_TOTAL_COUNT] !== true) {
|
|
903
|
-
result.push(PROPERTY_NAME_TOTAL_COUNT);
|
|
904
|
-
}
|
|
905
|
-
insertTypeName(seenFields, result);
|
|
906
|
-
}
|
|
907
|
-
function insertTypeName(seenFields, result) {
|
|
908
|
-
if (seenFields[TYPENAME_FIELD$1] !== true) {
|
|
909
|
-
result.unshift(TYPENAME_FIELD$1);
|
|
910
|
-
}
|
|
911
|
-
}
|
|
912
|
-
|
|
913
|
-
function createCustomFieldRead(luvio, sel, variables) {
|
|
914
|
-
if (sel.type === 'Connection') {
|
|
915
|
-
return createRead$2(luvio, sel, variables);
|
|
916
|
-
}
|
|
917
|
-
return createRead$3(luvio, sel, variables);
|
|
918
|
-
}
|
|
919
|
-
function createRead$1(luvio, ast, variables) {
|
|
920
|
-
if (ast.kind === 'CustomFieldSelection') {
|
|
921
|
-
return createCustomFieldRead(luvio, ast, variables);
|
|
922
|
-
}
|
|
923
|
-
if (ast.kind === 'FragmentSpread' ||
|
|
924
|
-
ast.kind === 'InlineFragment' ||
|
|
925
|
-
ast.kind === 'ScalarFieldSelection') {
|
|
926
|
-
// eslint-disable-next-line @salesforce/lds/no-error-in-production
|
|
927
|
-
throw new Error('"FragmentSpread" and "InlineFragment" currently not supported');
|
|
928
|
-
}
|
|
929
|
-
return genericCreateRead(luvio, ast, variables);
|
|
930
|
-
}
|
|
931
|
-
var genericCreateRead = function (luvio, ast, variables) {
|
|
932
|
-
var selections = ast.luvioSelections === undefined ? [] : ast.luvioSelections;
|
|
933
|
-
return function (source, builder) {
|
|
934
|
-
var sink = {};
|
|
935
|
-
for (var i = 0, len = selections.length; i < len; i += 1) {
|
|
936
|
-
var sel = getLuvioFieldNodeSelection(selections[i]);
|
|
937
|
-
var fieldName = sel.name, alias = sel.alias;
|
|
938
|
-
var propertyName = alias === undefined ? fieldName : alias;
|
|
939
|
-
builder.enterPath(fieldName);
|
|
940
|
-
switch (sel.kind) {
|
|
941
|
-
case 'ScalarFieldSelection':
|
|
942
|
-
readScalarFieldSelection(builder, source, fieldName, sink);
|
|
943
|
-
break;
|
|
944
|
-
default: {
|
|
945
|
-
var data = followLink(luvio, sel, builder, source[render(sel, variables)], variables);
|
|
946
|
-
builder.assignNonScalar(sink, propertyName, data);
|
|
947
|
-
}
|
|
948
|
-
}
|
|
949
|
-
builder.exitPath();
|
|
950
|
-
}
|
|
951
|
-
return sink;
|
|
952
|
-
};
|
|
953
|
-
};
|
|
954
|
-
|
|
955
|
-
var PropertyLookupResultState;
|
|
956
|
-
(function (PropertyLookupResultState) {
|
|
957
|
-
PropertyLookupResultState[PropertyLookupResultState["Missing"] = 0] = "Missing";
|
|
958
|
-
PropertyLookupResultState[PropertyLookupResultState["Present"] = 1] = "Present";
|
|
959
|
-
})(PropertyLookupResultState || (PropertyLookupResultState = {}));
|
|
960
|
-
var objectPrototypeHasOwnProperty = Object.prototype.hasOwnProperty;
|
|
961
|
-
function propertyLookup(builder, key, source) {
|
|
962
|
-
if (objectPrototypeHasOwnProperty.call(source, key) === false) {
|
|
963
|
-
builder.markMissing();
|
|
964
|
-
return {
|
|
965
|
-
state: PropertyLookupResultState.Missing,
|
|
966
|
-
};
|
|
967
|
-
}
|
|
968
|
-
return {
|
|
969
|
-
state: PropertyLookupResultState.Present,
|
|
970
|
-
value: source[key],
|
|
971
|
-
};
|
|
972
|
-
}
|
|
973
|
-
function markStoreResolveResultSeen(builder, state) {
|
|
974
|
-
var redirects = state.redirects, resolvedKey = state.resolvedKey;
|
|
975
|
-
builder.markSeenId(resolvedKey);
|
|
976
|
-
var len = redirects.length;
|
|
977
|
-
if (len === 0) {
|
|
978
|
-
return;
|
|
979
|
-
}
|
|
980
|
-
for (var i = 0; i < len; i += 1) {
|
|
981
|
-
builder.markSeenId(redirects[i]);
|
|
982
|
-
}
|
|
983
|
-
}
|
|
984
|
-
function resolveKey(builder, key) {
|
|
985
|
-
var StoreResolveResultState = builder.StoreResolveResultState;
|
|
986
|
-
var lookup = builder.storeLookup(key);
|
|
987
|
-
markStoreResolveResultSeen(builder, lookup);
|
|
988
|
-
switch (lookup.state) {
|
|
989
|
-
case StoreResolveResultState.NotPresent:
|
|
990
|
-
builder.markMissingLink(key);
|
|
991
|
-
return;
|
|
992
|
-
case StoreResolveResultState.Stale:
|
|
993
|
-
builder.markStale();
|
|
994
|
-
return lookup;
|
|
995
|
-
case StoreResolveResultState.Error:
|
|
996
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
997
|
-
throw new Error('TODO: Implement error links');
|
|
998
|
-
}
|
|
999
|
-
else {
|
|
1000
|
-
return;
|
|
1001
|
-
}
|
|
1002
|
-
}
|
|
1003
|
-
return lookup;
|
|
1004
|
-
}
|
|
1005
|
-
function resolveLink(builder, storeLink) {
|
|
1006
|
-
var StoreLinkStateValues = builder.StoreLinkStateValues;
|
|
1007
|
-
var linkState = builder.getLinkState(storeLink);
|
|
1008
|
-
switch (linkState.state) {
|
|
1009
|
-
case StoreLinkStateValues.RefNotPresent:
|
|
1010
|
-
case StoreLinkStateValues.NotPresent:
|
|
1011
|
-
case StoreLinkStateValues.Missing:
|
|
1012
|
-
builder.markMissing();
|
|
1013
|
-
return;
|
|
1014
|
-
case StoreLinkStateValues.Pending:
|
|
1015
|
-
builder.markPending();
|
|
1016
|
-
return;
|
|
1017
|
-
case StoreLinkStateValues.Null:
|
|
1018
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
1019
|
-
throw new Error("TODO: Invalid Link State. Link on \"".concat(builder.currentPath.fullPath, "\""));
|
|
1020
|
-
}
|
|
1021
|
-
else {
|
|
1022
|
-
return;
|
|
1023
|
-
}
|
|
1024
|
-
}
|
|
1025
|
-
var __ref = linkState.key;
|
|
1026
|
-
return resolveKey(builder, __ref);
|
|
1027
|
-
}
|
|
1028
|
-
function followLink(luvio, sel, builder, storeLink, variables) {
|
|
1029
|
-
var linkState = resolveLink(builder, storeLink);
|
|
1030
|
-
if (linkState === undefined) {
|
|
1031
|
-
return;
|
|
1032
|
-
}
|
|
1033
|
-
var value = linkState.value;
|
|
1034
|
-
return createRead$1(luvio, sel, variables)(value, builder);
|
|
1035
|
-
}
|
|
1036
|
-
function getLuvioFieldNodeSelection(ast) {
|
|
1037
|
-
var kind = ast.kind;
|
|
1038
|
-
if (kind === 'FragmentSpread' || kind === 'InlineFragment') {
|
|
1039
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
1040
|
-
throw new Error('"FragmentSpread" and "InlineFragment" currently not supported');
|
|
1041
|
-
}
|
|
1042
|
-
}
|
|
1043
|
-
return ast;
|
|
1044
|
-
}
|
|
1045
|
-
|
|
1046
|
-
var TYPENAME_FIELD = '__typename';
|
|
1047
|
-
var KIND_OBJECT_FIELD_SELECTION = 'ObjectFieldSelection';
|
|
1048
|
-
function serializeFieldNodeName(node) {
|
|
1049
|
-
var name = node.name, alias = node.alias;
|
|
1050
|
-
return alias === undefined ? "".concat(name) : "".concat(alias, ": ").concat(name);
|
|
1051
|
-
}
|
|
1052
|
-
function serializeSelections(selections, state) {
|
|
1053
|
-
if (selections === undefined) {
|
|
1054
|
-
return '';
|
|
1055
|
-
}
|
|
1056
|
-
var str = '';
|
|
1057
|
-
for (var i = 0, len = selections.length; i < len; i += 1) {
|
|
1058
|
-
var def = serializeFieldNode(selections[i], state);
|
|
1059
|
-
str = "".concat(str).concat(def);
|
|
1060
|
-
}
|
|
1061
|
-
return str;
|
|
1062
|
-
}
|
|
1063
|
-
function serializeFieldNode(def, state) {
|
|
1064
|
-
var kind = def.kind;
|
|
1065
|
-
switch (kind) {
|
|
1066
|
-
case 'ObjectFieldSelection':
|
|
1067
|
-
return serializeObjectFieldNode(def, state);
|
|
1068
|
-
case 'CustomFieldSelection':
|
|
1069
|
-
return serializeCustomFieldNode(def, state);
|
|
1070
|
-
case 'ScalarFieldSelection':
|
|
1071
|
-
return serializeScalarFieldNode(def);
|
|
1072
|
-
}
|
|
1073
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
1074
|
-
throw new Error("Unable to serialize graphql query, unsupported field node \"".concat(kind, "\""));
|
|
1075
|
-
}
|
|
1076
|
-
return '';
|
|
1077
|
-
}
|
|
1078
|
-
function serializeObjectFieldNode(def, state) {
|
|
1079
|
-
var luvioSelections = def.luvioSelections, defArgs = def.arguments;
|
|
1080
|
-
var args = defArgs === undefined ? '' : "(".concat(serializeArguments(defArgs), ")");
|
|
1081
|
-
return "".concat(serializeFieldNodeName(def)).concat(args, " { ").concat(TYPENAME_FIELD, " ").concat(serializeSelections(luvioSelections, state), " }");
|
|
1082
|
-
}
|
|
1083
|
-
function serializeCustomFieldNode(def, state) {
|
|
1084
|
-
var type = def.type;
|
|
1085
|
-
switch (type) {
|
|
1086
|
-
case 'Connection':
|
|
1087
|
-
return serialize(def, state);
|
|
1088
|
-
case 'Record':
|
|
1089
|
-
return serializeCustomFieldRecord(def, state);
|
|
1090
|
-
}
|
|
1091
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
1092
|
-
throw new Error("Unable to serialize graphql query, unsupported CustomField type \"".concat(type, "\""));
|
|
1093
|
-
}
|
|
1094
|
-
return '';
|
|
1095
|
-
}
|
|
1096
|
-
function serializeScalarFieldNode(def) {
|
|
1097
|
-
return "".concat(serializeFieldNodeName(def), ", ");
|
|
1098
|
-
}
|
|
1099
|
-
function serializeRecordSelections(selections, state) {
|
|
1100
|
-
if (selections === undefined) {
|
|
1101
|
-
return '';
|
|
1102
|
-
}
|
|
1103
|
-
var str = '';
|
|
1104
|
-
for (var i = 0, len = selections.length; i < len; i += 1) {
|
|
1105
|
-
var sel = getLuvioFieldNodeSelection(selections[i]);
|
|
1106
|
-
sel.name;
|
|
1107
|
-
var def = isLuvioFieldNodeObjectFieldNode(sel)
|
|
1108
|
-
? serializeObjectFieldNodeUnderRecord(sel)
|
|
1109
|
-
: serializeFieldNode(sel, state);
|
|
1110
|
-
str = "".concat(str).concat(def);
|
|
1111
|
-
}
|
|
1112
|
-
return str;
|
|
1113
|
-
}
|
|
1114
|
-
function isLuvioFieldNodeObjectFieldNode(node) {
|
|
1115
|
-
return node.kind === KIND_OBJECT_FIELD_SELECTION;
|
|
1116
|
-
}
|
|
1117
|
-
function serializeObjectFieldNodeUnderRecord(node) {
|
|
1118
|
-
var luvioSelections = node.luvioSelections, nodeArgs = node.arguments, nodeName = node.name;
|
|
1119
|
-
var fields = {};
|
|
1120
|
-
var result = "";
|
|
1121
|
-
if (luvioSelections === undefined) {
|
|
1122
|
-
// eslint-disable-next-line @salesforce/lds/no-error-in-production
|
|
1123
|
-
throw new Error('selection should not be empty for ObjectFieldNodeUnderRecord');
|
|
1124
|
-
}
|
|
1125
|
-
var luvioSelectionsLength = luvioSelections.length;
|
|
1126
|
-
for (var i = 0; i < luvioSelectionsLength; i++) {
|
|
1127
|
-
var sel = getLuvioFieldNodeSelection(luvioSelections[i]);
|
|
1128
|
-
var name_2 = sel.name;
|
|
1129
|
-
if (sel.kind !== 'ScalarFieldSelection') {
|
|
1130
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
1131
|
-
throw new Error("Invalid selection for ".concat(nodeName, ". ").concat(nodeName, " appears to be a Record, but is missing @resource(type: \"Record\")"));
|
|
1132
|
-
}
|
|
1133
|
-
}
|
|
1134
|
-
if (RECORD_DEFAULT_FIELD_VALUES.indexOf(name_2) === -1) {
|
|
1135
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
1136
|
-
throw new Error("Invalid selection for \"".concat(nodeName, ".").concat(name_2, "\". Only ").concat(RECORD_DEFAULT_FIELD_VALUES.join(', '), " are supported. If \"").concat(nodeName, "\" is a spanning Record, please include @resource(type: \"Record\") directive."));
|
|
1137
|
-
}
|
|
1138
|
-
}
|
|
1139
|
-
fields[name_2] = true;
|
|
1140
|
-
result = "".concat(result).concat(serializeScalarFieldNode(sel));
|
|
1141
|
-
}
|
|
1142
|
-
result = appendRecordDefaultFieldValues(result, fields);
|
|
1143
|
-
var args = nodeArgs === undefined ? '' : "(".concat(serializeArguments(nodeArgs), ")");
|
|
1144
|
-
return "".concat(serializeFieldNodeName(node)).concat(args, " { ").concat(TYPENAME_FIELD, " ").concat(result, " }");
|
|
1145
|
-
}
|
|
1146
|
-
function appendRecordDefaultFieldValues(fieldValues, fieldValuesMap) {
|
|
1147
|
-
var str = fieldValues;
|
|
1148
|
-
for (var i = 0, len = RECORD_DEFAULT_FIELD_VALUES.length; i < len; i++) {
|
|
1149
|
-
var defaultField = RECORD_DEFAULT_FIELD_VALUES[i];
|
|
1150
|
-
if (fieldValuesMap[defaultField] !== true) {
|
|
1151
|
-
str = "".concat(str).concat(defaultField, ", ");
|
|
1152
|
-
}
|
|
1153
|
-
}
|
|
1154
|
-
return str;
|
|
1155
|
-
}
|
|
1156
|
-
function appendSpanningRecordIds(luvioSelections) {
|
|
1157
|
-
if (luvioSelections === undefined) {
|
|
1158
|
-
return undefined;
|
|
1159
|
-
}
|
|
1160
|
-
//add record ref ids
|
|
1161
|
-
var spanningRecordIdFields = [];
|
|
1162
|
-
var selections = luvioSelections;
|
|
1163
|
-
//Find all fields with a record type declaration and add the corresponding
|
|
1164
|
-
//reference ID.
|
|
1165
|
-
// TODO [W-11342283]: This approach uses a naming pattern that is brittle and not
|
|
1166
|
-
// guaranteed to work in the long run. A more correct approach is to thread through
|
|
1167
|
-
// ObjectInfo schemas and use its mapping definitions.
|
|
1168
|
-
for (var i = 0; i < selections.length; i++) {
|
|
1169
|
-
var selection = selections[i];
|
|
1170
|
-
if (selection.kind === 'CustomFieldSelection' && selection.type === 'Record') {
|
|
1171
|
-
var customFieldMatches = selection.name.match(/(.*__)r$/);
|
|
1172
|
-
if (customFieldMatches) {
|
|
1173
|
-
// For `FSL__Related_Service__r {...}`, inject `FSL__Related_Service__c { value } as a peer field`
|
|
1174
|
-
var captureGroup = customFieldMatches[1];
|
|
1175
|
-
spanningRecordIdFields.push("".concat(captureGroup, "c"));
|
|
1176
|
-
}
|
|
1177
|
-
else {
|
|
1178
|
-
// For `Owner {...}`, inject `OwnerId { value } as a peer field`
|
|
1179
|
-
spanningRecordIdFields.push("".concat(selection.name, "Id"));
|
|
1180
|
-
}
|
|
1181
|
-
}
|
|
1182
|
-
}
|
|
1183
|
-
var _loop_1 = function (i) {
|
|
1184
|
-
var idField = spanningRecordIdFields[i];
|
|
1185
|
-
if (selections.findIndex(function (e) { return e.kind === 'ObjectFieldSelection' && e.name === idField; }) >
|
|
1186
|
-
-1) {
|
|
1187
|
-
return "continue";
|
|
1188
|
-
}
|
|
1189
|
-
selections.push({
|
|
1190
|
-
kind: 'ObjectFieldSelection',
|
|
1191
|
-
name: idField,
|
|
1192
|
-
luvioSelections: [{ kind: 'ScalarFieldSelection', name: 'value' }],
|
|
1193
|
-
});
|
|
1194
|
-
};
|
|
1195
|
-
//Add all missing reference IDs to the set of selections
|
|
1196
|
-
for (var i = 0; i < spanningRecordIdFields.length; i++) {
|
|
1197
|
-
_loop_1(i);
|
|
1198
|
-
}
|
|
1199
|
-
return selections;
|
|
1200
|
-
}
|
|
1201
|
-
function serializeCustomFieldRecord(def, state) {
|
|
1202
|
-
var luvioSelections = def.luvioSelections;
|
|
1203
|
-
if (state.fragments[defaultRecordFieldsFragmentName] === undefined) {
|
|
1204
|
-
state.fragments[defaultRecordFieldsFragmentName] = defaultRecordFieldsFragment;
|
|
1205
|
-
}
|
|
1206
|
-
var selections = appendSpanningRecordIds(luvioSelections);
|
|
1207
|
-
return "".concat(serializeFieldNodeName(def), " { ").concat(serializeRecordSelections(selections, state), " ...").concat(defaultRecordFieldsFragmentName, " }");
|
|
1208
|
-
}
|
|
1209
|
-
function serializeArguments(argDefinitions) {
|
|
1210
|
-
if (argDefinitions === undefined) {
|
|
1211
|
-
return '';
|
|
1212
|
-
}
|
|
1213
|
-
var str = '';
|
|
1214
|
-
for (var i = 0, len = argDefinitions.length; i < len; i += 1) {
|
|
1215
|
-
var def = serializeArgument(argDefinitions[i]);
|
|
1216
|
-
if (i !== 0) {
|
|
1217
|
-
def = " ".concat(def);
|
|
1218
|
-
}
|
|
1219
|
-
str = "".concat(str).concat(def);
|
|
1220
|
-
}
|
|
1221
|
-
return str;
|
|
1222
|
-
}
|
|
1223
|
-
function serializeArgument(argDefinition) {
|
|
1224
|
-
var name = argDefinition.name, value = argDefinition.value;
|
|
1225
|
-
return "".concat(name, ": ").concat(serializeValueNode(value));
|
|
1226
|
-
}
|
|
1227
|
-
|
|
1228
|
-
function serializeValueNode(valueDefinition) {
|
|
1229
|
-
var kind = valueDefinition.kind;
|
|
1230
|
-
switch (kind) {
|
|
1231
|
-
case 'ObjectValue':
|
|
1232
|
-
return serializeObjectValueNode(valueDefinition);
|
|
1233
|
-
case 'StringValue':
|
|
1234
|
-
return serializeStringValueNode(valueDefinition);
|
|
1235
|
-
case 'NullValue':
|
|
1236
|
-
return 'null';
|
|
1237
|
-
case 'FloatValue':
|
|
1238
|
-
case 'IntValue':
|
|
1239
|
-
case 'BooleanValue':
|
|
1240
|
-
case 'EnumValue':
|
|
1241
|
-
return valueDefinition.value;
|
|
1242
|
-
case 'Variable':
|
|
1243
|
-
return serializeVariableNode(valueDefinition);
|
|
1244
|
-
case 'ListValue':
|
|
1245
|
-
return serializeListValueNode(valueDefinition);
|
|
1246
|
-
}
|
|
1247
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
1248
|
-
throw new Error("Unable to serialize graphql query, unsupported value node \"".concat(kind, "\""));
|
|
1249
|
-
}
|
|
1250
|
-
}
|
|
1251
|
-
function serializeVariableNode(variableNode) {
|
|
1252
|
-
return "$".concat(variableNode.name);
|
|
1253
|
-
}
|
|
1254
|
-
function serializeListValueNode(listNode) {
|
|
1255
|
-
var values = listNode.values;
|
|
1256
|
-
if (values.length === 0) {
|
|
1257
|
-
return '';
|
|
1258
|
-
}
|
|
1259
|
-
var str = '';
|
|
1260
|
-
for (var i = 0, len = values.length; i < len; i += 1) {
|
|
1261
|
-
str = "".concat(str).concat(serializeValueNode(values[i]), ", ");
|
|
1262
|
-
}
|
|
1263
|
-
return "[".concat(str.substring(0, str.length - 2), "]");
|
|
1264
|
-
}
|
|
1265
|
-
function serializeStringValueNode(literalValueNode) {
|
|
1266
|
-
return "\"".concat(literalValueNode.value, "\"");
|
|
1267
|
-
}
|
|
1268
|
-
function serializeObjectValueNode(objectValueDefinition) {
|
|
1269
|
-
var fields = objectValueDefinition.fields;
|
|
1270
|
-
var str = [];
|
|
1271
|
-
var fieldKeys = keys(fields);
|
|
1272
|
-
for (var i = 0, len = fieldKeys.length; i < len; i += 1) {
|
|
1273
|
-
var fieldKey = fieldKeys[i];
|
|
1274
|
-
str.push("".concat(fieldKey, ": ").concat(serializeValueNode(fields[fieldKey])));
|
|
1275
|
-
}
|
|
1276
|
-
return "{ ".concat(str.join(', '), " }");
|
|
1277
|
-
}
|
|
1278
|
-
function serializeVariableDefinitions(definitons) {
|
|
1279
|
-
if (definitons === undefined || definitons.length === 0) {
|
|
1280
|
-
return '';
|
|
1281
|
-
}
|
|
1282
|
-
var str = '';
|
|
1283
|
-
for (var i = 0, len = definitons.length; i < len; i += 1) {
|
|
1284
|
-
var def = serializeVariableDefinitionNode(definitons[i]);
|
|
1285
|
-
str = "".concat(str).concat(def, ", ");
|
|
1286
|
-
}
|
|
1287
|
-
return " (".concat(str.substring(0, str.length - 2), ")");
|
|
1288
|
-
}
|
|
1289
|
-
function serializeVariableDefinitionNode(def) {
|
|
1290
|
-
var variable = def.variable, type = def.type, defaultValue = def.defaultValue;
|
|
1291
|
-
return defaultValue === undefined
|
|
1292
|
-
? "$".concat(variable.name, ": ").concat(serializeTypeNode(type))
|
|
1293
|
-
: "$".concat(variable.name, ": ").concat(serializeTypeNode(type), " = ").concat(serializeValueNode(defaultValue));
|
|
1294
|
-
}
|
|
1295
|
-
function serializeTypeNode(type) {
|
|
1296
|
-
var kind = type.kind;
|
|
1297
|
-
switch (kind) {
|
|
1298
|
-
case 'NamedType':
|
|
1299
|
-
return serializeNamedTypeNode(type);
|
|
1300
|
-
case 'ListType':
|
|
1301
|
-
return serializeListTypeNode(type);
|
|
1302
|
-
}
|
|
1303
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
1304
|
-
throw new Error("Unable to serialize graphql query, unsupported variable definition type node \"".concat(type.kind, "\""));
|
|
1305
|
-
}
|
|
1306
|
-
return '';
|
|
1307
|
-
}
|
|
1308
|
-
function serializeNamedTypeNode(type) {
|
|
1309
|
-
return type.name;
|
|
1310
|
-
}
|
|
1311
|
-
function serializeListTypeNode(type) {
|
|
1312
|
-
return "[".concat(serializeTypeNode(type.type), "]");
|
|
1313
|
-
}
|
|
1314
|
-
function serializeOperationNode(def, state) {
|
|
1315
|
-
var kind = def.kind;
|
|
1316
|
-
switch (kind) {
|
|
1317
|
-
case 'OperationDefinition':
|
|
1318
|
-
return serializeOperationDefinition(def, state);
|
|
1319
|
-
}
|
|
1320
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
1321
|
-
throw new Error("Unable to serialize graphql query, unsupported OperationDefinition type \"".concat(kind, "\""));
|
|
1322
|
-
}
|
|
1323
|
-
}
|
|
1324
|
-
function serializeOperationDefinition(def, state) {
|
|
1325
|
-
var operation = def.operation, luvioSelections = def.luvioSelections, name = def.name, variableDefinitions = def.variableDefinitions;
|
|
1326
|
-
var nameStr = name === undefined ? ' ' : " ".concat(name, " ");
|
|
1327
|
-
return "".concat(operation).concat(nameStr).concat(serializeVariableDefinitions(variableDefinitions), "{ ").concat(TYPENAME_FIELD, " ").concat(serializeSelections(luvioSelections, state), " }");
|
|
1328
|
-
}
|
|
1329
|
-
function applyFragments(str, fragments) {
|
|
1330
|
-
var appliedString = str;
|
|
1331
|
-
var fragmentNames = Object.keys(fragments);
|
|
1332
|
-
for (var i = 0, len = fragmentNames.length; i < len; i += 1) {
|
|
1333
|
-
var name_1 = fragmentNames[i];
|
|
1334
|
-
appliedString = "".concat(appliedString, " ").concat(fragments[name_1]);
|
|
1335
|
-
}
|
|
1336
|
-
return appliedString;
|
|
1337
|
-
}
|
|
1338
|
-
function astToString(ast) {
|
|
1339
|
-
var definitions = ast.definitions;
|
|
1340
|
-
var state = {
|
|
1341
|
-
fragments: {},
|
|
1342
|
-
};
|
|
1343
|
-
var str = '';
|
|
1344
|
-
for (var i = 0, len = definitions.length; i < len; i += 1) {
|
|
1345
|
-
var def = serializeOperationNode(definitions[i], state);
|
|
1346
|
-
str = "".concat(str).concat(def);
|
|
1347
|
-
}
|
|
1348
|
-
return applyFragments(str, state.fragments);
|
|
1349
|
-
}
|
|
1350
|
-
|
|
1351
|
-
function isGraphQLVariables(unknown) {
|
|
1352
|
-
return untrustedIsObject(unknown);
|
|
1353
|
-
}
|
|
1354
|
-
function validateVariableDefinitions(definitons, variables) {
|
|
1355
|
-
var errors = [];
|
|
1356
|
-
for (var i = 0, len = definitons.length; i < len; i += 1) {
|
|
1357
|
-
var _a = definitons[i], variable = _a.variable, type = _a.type, defaultValue = _a.defaultValue;
|
|
1358
|
-
var value = getVariableValue(variable.name, variables, defaultValue);
|
|
1359
|
-
if (value === undefined) {
|
|
1360
|
-
errors.push("Variable $".concat(variable.name, " has an undefined value provided for it."));
|
|
1361
|
-
}
|
|
1362
|
-
if (type.kind === 'NonNullType' && value === null) {
|
|
1363
|
-
errors.push("Expected a non-null value to be provided as value for $".concat(variable.name));
|
|
1364
|
-
}
|
|
1365
|
-
if (type.kind === 'ListType' && value !== null && !Array.isArray(value)) {
|
|
1366
|
-
errors.push("Expected a list to be provided as value for $".concat(variable.name));
|
|
1367
|
-
}
|
|
1368
|
-
}
|
|
1369
|
-
return errors;
|
|
1370
|
-
}
|
|
1371
|
-
function getVariableValue(name, variables, defaultValue) {
|
|
1372
|
-
if (name in variables) {
|
|
1373
|
-
return variables[name];
|
|
1374
|
-
}
|
|
1375
|
-
if (defaultValue === undefined) {
|
|
1376
|
-
return null;
|
|
1377
|
-
}
|
|
1378
|
-
return defaultValue;
|
|
1379
|
-
}
|
|
1380
|
-
|
|
1381
|
-
function validate$1(ast, variables) {
|
|
1382
|
-
var variableDefinitions = ast.variableDefinitions;
|
|
1383
|
-
var errors = [];
|
|
1384
|
-
if (variableDefinitions !== undefined) {
|
|
1385
|
-
errors.push.apply(errors, validateVariableDefinitions(variableDefinitions, variables));
|
|
1386
|
-
}
|
|
1387
|
-
return errors;
|
|
1388
|
-
}
|
|
1389
|
-
|
|
1390
|
-
function isLuvioDocumentNode(unknown) {
|
|
1391
|
-
if (untrustedIsObject(unknown) === true &&
|
|
1392
|
-
hasOwnProperty.call(unknown, 'kind') === true &&
|
|
1393
|
-
hasOwnProperty.call(unknown, 'definitions') === true) {
|
|
1394
|
-
return (typeof unknown.kind === 'string' &&
|
|
1395
|
-
isArray(unknown.definitions));
|
|
1396
|
-
}
|
|
1397
|
-
return false;
|
|
1398
|
-
}
|
|
1399
|
-
var createRead = function (luvio, ast, variables) {
|
|
1400
|
-
var definitions = ast.definitions === undefined ? [] : ast.definitions;
|
|
1401
|
-
return function (source, builder) {
|
|
1402
|
-
builder.enterPath('data');
|
|
1403
|
-
var sink = {};
|
|
1404
|
-
for (var i = 0, len = definitions.length; i < len; i += 1) {
|
|
1405
|
-
var def = definitions[i];
|
|
1406
|
-
if (def.kind !== 'OperationDefinition') {
|
|
1407
|
-
// eslint-disable-next-line @salesforce/lds/no-error-in-production
|
|
1408
|
-
throw new Error("Unsupported document definition \"".concat(def.kind, "\""));
|
|
1409
|
-
}
|
|
1410
|
-
var data = createRead$1(luvio, def, variables)(source, builder);
|
|
1411
|
-
sink = __assign(__assign({}, sink), data);
|
|
1412
|
-
}
|
|
1413
|
-
var gqlData = {};
|
|
1414
|
-
builder.assignNonScalar(gqlData, 'data', sink);
|
|
1415
|
-
builder.exitPath();
|
|
1416
|
-
builder.enterPath('errors');
|
|
1417
|
-
builder.assignNonScalar(gqlData, 'errors', []);
|
|
1418
|
-
builder.exitPath();
|
|
1419
|
-
return gqlData;
|
|
1420
|
-
};
|
|
1421
|
-
};
|
|
1422
|
-
function createIngest(ast, variables) {
|
|
1423
|
-
var definitions = ast.definitions === undefined ? [] : ast.definitions;
|
|
1424
|
-
return function (data, path, luvio, store, timestamp) {
|
|
1425
|
-
var key = path.fullPath;
|
|
1426
|
-
for (var i = 0, len = definitions.length; i < len; i += 1) {
|
|
1427
|
-
var def = definitions[i];
|
|
1428
|
-
if (def.kind !== 'OperationDefinition') {
|
|
1429
|
-
// eslint-disable-next-line @salesforce/lds/no-error-in-production
|
|
1430
|
-
throw new Error("Unsupported document definition \"".concat(def.kind, "\""));
|
|
1431
|
-
}
|
|
1432
|
-
createIngest$2(def, variables)(data, {
|
|
1433
|
-
parent: null,
|
|
1434
|
-
fullPath: key,
|
|
1435
|
-
propertyName: null,
|
|
1436
|
-
}, luvio, store, timestamp);
|
|
1437
|
-
}
|
|
1438
|
-
return {
|
|
1439
|
-
__ref: key,
|
|
1440
|
-
};
|
|
1441
|
-
};
|
|
1442
|
-
}
|
|
1443
|
-
function validate(ast, variables) {
|
|
1444
|
-
var errors = [];
|
|
1445
|
-
var definitions = ast.definitions;
|
|
1446
|
-
for (var i = 0, len = definitions.length; i < len; i += 1) {
|
|
1447
|
-
var def = definitions[i];
|
|
1448
|
-
if (def.kind !== 'OperationDefinition') {
|
|
1449
|
-
errors.push("Unsupported document definition \"".concat(def.kind, "\""));
|
|
1450
|
-
}
|
|
1451
|
-
else {
|
|
1452
|
-
errors.push.apply(errors, validate$1(def, variables));
|
|
1453
|
-
}
|
|
1454
|
-
}
|
|
1455
|
-
return errors;
|
|
1456
|
-
}
|
|
1457
|
-
|
|
1458
|
-
var storeEval = undefined;
|
|
1459
|
-
var configuration = {
|
|
1460
|
-
setStoreEval: function (storeEvalArg) {
|
|
1461
|
-
storeEval = storeEvalArg;
|
|
1462
|
-
},
|
|
1463
|
-
};
|
|
1464
|
-
|
|
1465
|
-
var assignedToMe = {
|
|
1466
|
-
kind: 'CustomFieldSelection',
|
|
1467
|
-
name: 'ServiceResources',
|
|
1468
|
-
type: 'Connection',
|
|
1469
|
-
luvioSelections: [
|
|
1470
|
-
{
|
|
1471
|
-
kind: 'ObjectFieldSelection',
|
|
1472
|
-
name: 'edges',
|
|
1473
|
-
luvioSelections: [
|
|
1474
|
-
{
|
|
1475
|
-
kind: 'CustomFieldSelection',
|
|
1476
|
-
name: 'node',
|
|
1477
|
-
type: 'Record',
|
|
1478
|
-
luvioSelections: [
|
|
1479
|
-
{
|
|
1480
|
-
kind: 'ObjectFieldSelection',
|
|
1481
|
-
name: 'ServiceResourceId',
|
|
1482
|
-
luvioSelections: [
|
|
1483
|
-
{
|
|
1484
|
-
kind: 'ScalarFieldSelection',
|
|
1485
|
-
name: 'value',
|
|
1486
|
-
},
|
|
1487
|
-
],
|
|
1488
|
-
},
|
|
1489
|
-
{
|
|
1490
|
-
kind: 'ObjectFieldSelection',
|
|
1491
|
-
name: 'ServiceAppointmentId',
|
|
1492
|
-
luvioSelections: [
|
|
1493
|
-
{
|
|
1494
|
-
kind: 'ScalarFieldSelection',
|
|
1495
|
-
name: 'value',
|
|
1496
|
-
},
|
|
1497
|
-
],
|
|
1498
|
-
},
|
|
1499
|
-
{
|
|
1500
|
-
kind: 'CustomFieldSelection',
|
|
1501
|
-
name: 'ServiceResource',
|
|
1502
|
-
type: 'Record',
|
|
1503
|
-
luvioSelections: [
|
|
1504
|
-
{
|
|
1505
|
-
kind: 'ScalarFieldSelection',
|
|
1506
|
-
name: 'Id',
|
|
1507
|
-
},
|
|
1508
|
-
{
|
|
1509
|
-
kind: 'ObjectFieldSelection',
|
|
1510
|
-
name: 'RelatedRecordId',
|
|
1511
|
-
luvioSelections: [
|
|
1512
|
-
{
|
|
1513
|
-
kind: 'ScalarFieldSelection',
|
|
1514
|
-
name: 'value',
|
|
1515
|
-
},
|
|
1516
|
-
],
|
|
1517
|
-
},
|
|
1518
|
-
],
|
|
1519
|
-
},
|
|
1520
|
-
],
|
|
1521
|
-
},
|
|
1522
|
-
],
|
|
1523
|
-
},
|
|
1524
|
-
],
|
|
1525
|
-
};
|
|
1526
|
-
function shouldInjectFields(ast) {
|
|
1527
|
-
var injectScope = false;
|
|
1528
|
-
var recordNodes = findRecordSelections(ast);
|
|
1529
|
-
if (recordNodes !== undefined && recordNodes.length > 0) {
|
|
1530
|
-
for (var _i = 0, recordNodes_1 = recordNodes; _i < recordNodes_1.length; _i++) {
|
|
1531
|
-
var recordNode = recordNodes_1[_i];
|
|
1532
|
-
if (recordNode.arguments !== undefined) {
|
|
1533
|
-
for (var _a = 0, _b = recordNode.arguments; _a < _b.length; _a++) {
|
|
1534
|
-
var argument = _b[_a];
|
|
1535
|
-
if (argument.name === 'scope' &&
|
|
1536
|
-
argument.value.kind === 'EnumValue' &&
|
|
1537
|
-
argument.value.value === 'ASSIGNEDTOME') {
|
|
1538
|
-
injectScope = true;
|
|
1539
|
-
break;
|
|
1540
|
-
}
|
|
1541
|
-
}
|
|
1542
|
-
}
|
|
1543
|
-
}
|
|
1544
|
-
}
|
|
1545
|
-
return injectScope;
|
|
1546
|
-
}
|
|
1547
|
-
function injectFieldsGQL(ast) {
|
|
1548
|
-
return injectScopeFields(ast);
|
|
1549
|
-
}
|
|
1550
|
-
function injectScopeFields(ast) {
|
|
1551
|
-
var _a;
|
|
1552
|
-
var modifiedDocumentNode = {
|
|
1553
|
-
kind: 'Document',
|
|
1554
|
-
definitions: [
|
|
1555
|
-
{
|
|
1556
|
-
kind: 'OperationDefinition',
|
|
1557
|
-
operation: 'query',
|
|
1558
|
-
luvioSelections: [
|
|
1559
|
-
{
|
|
1560
|
-
kind: 'ObjectFieldSelection',
|
|
1561
|
-
name: 'uiapi',
|
|
1562
|
-
luvioSelections: [
|
|
1563
|
-
{
|
|
1564
|
-
kind: 'ObjectFieldSelection',
|
|
1565
|
-
name: 'query',
|
|
1566
|
-
luvioSelections: [],
|
|
1567
|
-
},
|
|
1568
|
-
],
|
|
1569
|
-
},
|
|
1570
|
-
],
|
|
1571
|
-
},
|
|
1572
|
-
],
|
|
1573
|
-
};
|
|
1574
|
-
var modifiedSelections = [];
|
|
1575
|
-
var recordNodes = findRecordSelections(ast);
|
|
1576
|
-
if (recordNodes !== undefined && recordNodes.length > 0) {
|
|
1577
|
-
// each record node represent a connection
|
|
1578
|
-
for (var _i = 0, recordNodes_2 = recordNodes; _i < recordNodes_2.length; _i++) {
|
|
1579
|
-
var recordNode = recordNodes_2[_i];
|
|
1580
|
-
modifiedSelections.push(injectConnectionForScope(recordNode));
|
|
1581
|
-
}
|
|
1582
|
-
}
|
|
1583
|
-
var queryNode = modifiedDocumentNode.definitions
|
|
1584
|
-
.filter(isOperationDefinition)
|
|
1585
|
-
.reduce(flatMap(luvioSelections), [])
|
|
1586
|
-
.filter(isObjectFieldSelection)
|
|
1587
|
-
.filter(named('uiapi'))
|
|
1588
|
-
.reduce(flatMap(luvioSelections), [])
|
|
1589
|
-
.filter(isObjectFieldSelection)
|
|
1590
|
-
.filter(named('query'))[0];
|
|
1591
|
-
(_a = queryNode.luvioSelections).push.apply(_a, modifiedSelections);
|
|
1592
|
-
return ast;
|
|
1593
|
-
}
|
|
1594
|
-
function injectConnectionForScope(connectionNode) {
|
|
1595
|
-
if (connectionNode.name === 'ServiceAppointment') {
|
|
1596
|
-
if (connectionNode.arguments !== undefined) {
|
|
1597
|
-
for (var _i = 0, _a = connectionNode.arguments; _i < _a.length; _i++) {
|
|
1598
|
-
var argument = _a[_i];
|
|
1599
|
-
if (argument.name === 'scope' &&
|
|
1600
|
-
argument.value.kind === 'EnumValue' &&
|
|
1601
|
-
argument.value.value === 'ASSIGNEDTOME') {
|
|
1602
|
-
var injectedConnctionNode = __assign({}, connectionNode);
|
|
1603
|
-
if (injectedConnctionNode.luvioSelections !== undefined) {
|
|
1604
|
-
var injectedNodes = injectedConnctionNode.luvioSelections
|
|
1605
|
-
.filter(isObjectFieldSelection)
|
|
1606
|
-
.filter(named('edges'))
|
|
1607
|
-
.reduce(flatMap(luvioSelections), [])
|
|
1608
|
-
.filter(isCustomFieldNode)
|
|
1609
|
-
.filter(named('node'));
|
|
1610
|
-
if (injectedNodes !== undefined && injectedNodes.length > 0) {
|
|
1611
|
-
var injectedNode = injectedNodes[0];
|
|
1612
|
-
if (injectedNode.luvioSelections !== undefined) {
|
|
1613
|
-
injectedNode.luvioSelections = mergeSelectionNodes(injectedNode.luvioSelections, [assignedToMe]);
|
|
1614
|
-
}
|
|
1615
|
-
}
|
|
1616
|
-
}
|
|
1617
|
-
return injectedConnctionNode;
|
|
1618
|
-
}
|
|
1619
|
-
}
|
|
1620
|
-
}
|
|
1621
|
-
}
|
|
1622
|
-
return __assign({}, connectionNode);
|
|
1623
|
-
}
|
|
1624
|
-
function mergeSelectionNodes(group1, group2) {
|
|
1625
|
-
var sameFields1 = [];
|
|
1626
|
-
var sameFields2 = [];
|
|
1627
|
-
var results = [];
|
|
1628
|
-
var _loop_1 = function (node2) {
|
|
1629
|
-
if (isCustomFieldNode(node2)) {
|
|
1630
|
-
var nodes1SameLevel = group1
|
|
1631
|
-
.filter(isCustomFieldNode)
|
|
1632
|
-
.filter(function (node1) { return node1.name === node2.name && node1.type === node2.type; });
|
|
1633
|
-
if (nodes1SameLevel.length > 0) {
|
|
1634
|
-
sameFields1.push.apply(sameFields1, nodes1SameLevel);
|
|
1635
|
-
sameFields2.push(node2);
|
|
1636
|
-
var mergedNode = nodes1SameLevel.reduce(function (accu, cur) { return mergeCustomFieldNodes(accu, cur); }, node2);
|
|
1637
|
-
results.push(mergedNode);
|
|
1638
|
-
}
|
|
1639
|
-
}
|
|
1640
|
-
else if (isObjectFieldSelection(node2)) {
|
|
1641
|
-
var nodes1SameLevel = group1
|
|
1642
|
-
.filter(isObjectFieldSelection)
|
|
1643
|
-
.filter(function (node1) { return node1.name === node2.name; });
|
|
1644
|
-
if (nodes1SameLevel.length > 0) {
|
|
1645
|
-
sameFields1.push.apply(sameFields1, nodes1SameLevel);
|
|
1646
|
-
sameFields2.push(node2);
|
|
1647
|
-
var mergedNode = nodes1SameLevel.reduce(function (accu, cur) { return mergeObjectFieldNodes(accu, cur); }, node2);
|
|
1648
|
-
results.push(mergedNode);
|
|
1649
|
-
}
|
|
1650
|
-
}
|
|
1651
|
-
};
|
|
1652
|
-
for (var _i = 0, group2_1 = group2; _i < group2_1.length; _i++) {
|
|
1653
|
-
var node2 = group2_1[_i];
|
|
1654
|
-
_loop_1(node2);
|
|
1655
|
-
}
|
|
1656
|
-
if (sameFields1.length > 0) {
|
|
1657
|
-
var differentNodes1 = group1.filter(function (node) { return !sameFields1.includes(node); });
|
|
1658
|
-
results.push.apply(results, differentNodes1);
|
|
1659
|
-
var differentNodes2 = group2.filter(function (node) { return !sameFields2.includes(node); });
|
|
1660
|
-
results.push.apply(results, differentNodes2);
|
|
1661
|
-
}
|
|
1662
|
-
else {
|
|
1663
|
-
return group1.concat(group2);
|
|
1664
|
-
}
|
|
1665
|
-
return results;
|
|
1666
|
-
}
|
|
1667
|
-
function mergeCustomFieldNodes(node1, node2) {
|
|
1668
|
-
var result = node1;
|
|
1669
|
-
if (node1.name === node2.name && node1.kind === node2.kind && node1.type === node2.type) {
|
|
1670
|
-
result = {
|
|
1671
|
-
kind: node1.kind,
|
|
1672
|
-
name: node1.name,
|
|
1673
|
-
type: node1.type,
|
|
1674
|
-
luvioSelections: [],
|
|
1675
|
-
};
|
|
1676
|
-
var selections_1 = [];
|
|
1677
|
-
var sameCustomFields1_1 = [];
|
|
1678
|
-
var sameCustomFields2_1 = [];
|
|
1679
|
-
var sameObjectFields1_1 = [];
|
|
1680
|
-
var sameObjectFields2_1 = [];
|
|
1681
|
-
var sameScalarFields1_1 = [];
|
|
1682
|
-
var sameScalarFields2_1 = [];
|
|
1683
|
-
if (node1.luvioSelections && node2.luvioSelections) {
|
|
1684
|
-
sameCustomFields1_1 = node1.luvioSelections
|
|
1685
|
-
.filter(isCustomFieldNode)
|
|
1686
|
-
.filter(function (childNode1) {
|
|
1687
|
-
if (node2.luvioSelections) {
|
|
1688
|
-
var sames = node2.luvioSelections
|
|
1689
|
-
.filter(isCustomFieldNode)
|
|
1690
|
-
.filter(function (childNode2) { return childNode2.name === childNode1.name; });
|
|
1691
|
-
if (sames.length > 0) {
|
|
1692
|
-
var mergedNode = sames.reduce(function (accu, cur) { return mergeCustomFieldNodes(accu, cur); }, childNode1);
|
|
1693
|
-
selections_1.push(mergedNode);
|
|
1694
|
-
result = __assign(__assign({}, result), { luvioSelections: selections_1 });
|
|
1695
|
-
sameCustomFields2_1.push.apply(sameCustomFields2_1, sames);
|
|
1696
|
-
return true;
|
|
1697
|
-
}
|
|
1698
|
-
}
|
|
1699
|
-
return false;
|
|
1700
|
-
});
|
|
1701
|
-
sameObjectFields1_1 = node1.luvioSelections
|
|
1702
|
-
.filter(isObjectFieldSelection)
|
|
1703
|
-
.filter(function (childNode1) {
|
|
1704
|
-
if (node2.luvioSelections) {
|
|
1705
|
-
var sames = node2.luvioSelections
|
|
1706
|
-
.filter(isObjectFieldSelection)
|
|
1707
|
-
.filter(function (childNode2) { return childNode2.name === childNode1.name; });
|
|
1708
|
-
if (sames.length > 0) {
|
|
1709
|
-
var mergedNode = sames.reduce(function (accu, cur) { return mergeObjectFieldNodes(accu, cur); }, childNode1);
|
|
1710
|
-
selections_1.push(mergedNode);
|
|
1711
|
-
result = __assign(__assign({}, result), { luvioSelections: selections_1 });
|
|
1712
|
-
sameObjectFields2_1.push.apply(sameObjectFields2_1, sames);
|
|
1713
|
-
return true;
|
|
1714
|
-
}
|
|
1715
|
-
}
|
|
1716
|
-
return false;
|
|
1717
|
-
});
|
|
1718
|
-
sameScalarFields1_1 = node1.luvioSelections
|
|
1719
|
-
.filter(isScalarFieldNode)
|
|
1720
|
-
.filter(function (childNode1) {
|
|
1721
|
-
if (node2.luvioSelections) {
|
|
1722
|
-
var sames = node2.luvioSelections
|
|
1723
|
-
.filter(isScalarFieldNode)
|
|
1724
|
-
.filter(function (childNode2) { return childNode2.name === childNode1.name; });
|
|
1725
|
-
if (sames.length > 0) {
|
|
1726
|
-
var mergedNode = sames.reduce(function (accu, cur) { return mergeScalarFieldNode(accu, cur); }, childNode1);
|
|
1727
|
-
selections_1.push(mergedNode);
|
|
1728
|
-
result = __assign(__assign({}, result), { luvioSelections: selections_1 });
|
|
1729
|
-
sameScalarFields2_1.push.apply(sameScalarFields2_1, sames);
|
|
1730
|
-
return true;
|
|
1731
|
-
}
|
|
1732
|
-
}
|
|
1733
|
-
return false;
|
|
1734
|
-
});
|
|
1735
|
-
if (sameCustomFields1_1.length > 0 ||
|
|
1736
|
-
sameObjectFields1_1.length > 0 ||
|
|
1737
|
-
sameScalarFields1_1.length > 0) {
|
|
1738
|
-
var diffNodes1 = node1.luvioSelections.filter(function (node) {
|
|
1739
|
-
return !sameCustomFields1_1.includes(node) &&
|
|
1740
|
-
!sameObjectFields1_1.includes(node) &&
|
|
1741
|
-
!sameScalarFields1_1.includes(node);
|
|
1742
|
-
});
|
|
1743
|
-
selections_1.push.apply(selections_1, diffNodes1);
|
|
1744
|
-
var diffNodes2 = node2.luvioSelections.filter(function (node) {
|
|
1745
|
-
return !sameCustomFields2_1.includes(node) &&
|
|
1746
|
-
!sameObjectFields2_1.includes(node) &&
|
|
1747
|
-
!sameScalarFields2_1.includes(node);
|
|
1748
|
-
});
|
|
1749
|
-
selections_1.push.apply(selections_1, diffNodes2);
|
|
1750
|
-
result = __assign(__assign({}, result), { luvioSelections: selections_1 });
|
|
1751
|
-
}
|
|
1752
|
-
else {
|
|
1753
|
-
selections_1.push.apply(selections_1, node1.luvioSelections);
|
|
1754
|
-
selections_1.push.apply(selections_1, node2.luvioSelections);
|
|
1755
|
-
result = __assign(__assign({}, result), { luvioSelections: selections_1 });
|
|
1756
|
-
}
|
|
1757
|
-
}
|
|
1758
|
-
else {
|
|
1759
|
-
if (node1.luvioSelections) {
|
|
1760
|
-
return node1;
|
|
1761
|
-
}
|
|
1762
|
-
if (node2.luvioSelections) {
|
|
1763
|
-
return node2;
|
|
1764
|
-
}
|
|
1765
|
-
}
|
|
1766
|
-
return result;
|
|
1767
|
-
}
|
|
1768
|
-
else {
|
|
1769
|
-
// eslint-disable-next-line
|
|
1770
|
-
throw new Error('The fields name needs to be same to be merged');
|
|
1771
|
-
}
|
|
1772
|
-
}
|
|
1773
|
-
function mergeObjectFieldNodes(node1, node2) {
|
|
1774
|
-
var result = node1;
|
|
1775
|
-
if (node1.name === node2.name && node1.kind === node2.kind) {
|
|
1776
|
-
result = {
|
|
1777
|
-
kind: node1.kind,
|
|
1778
|
-
name: node1.name,
|
|
1779
|
-
directives: node1.directives,
|
|
1780
|
-
luvioSelections: [],
|
|
1781
|
-
};
|
|
1782
|
-
var selections_2 = [];
|
|
1783
|
-
var sameCustomFields1_2 = [];
|
|
1784
|
-
var sameCustomFields2_2 = [];
|
|
1785
|
-
var sameObjectFields1_2 = [];
|
|
1786
|
-
var sameObjectFields2_2 = [];
|
|
1787
|
-
var sameScalarFields1_2 = [];
|
|
1788
|
-
var sameScalarFields2_2 = [];
|
|
1789
|
-
if (node1.luvioSelections && node2.luvioSelections) {
|
|
1790
|
-
sameCustomFields1_2 = node1.luvioSelections
|
|
1791
|
-
.filter(isCustomFieldNode)
|
|
1792
|
-
.filter(function (childNode1) {
|
|
1793
|
-
if (node2.luvioSelections) {
|
|
1794
|
-
var sames = node2.luvioSelections
|
|
1795
|
-
.filter(isCustomFieldNode)
|
|
1796
|
-
.filter(function (childNode2) { return childNode2.name === childNode1.name; });
|
|
1797
|
-
if (sames.length > 0) {
|
|
1798
|
-
var mergedNode = sames.reduce(function (accu, cur) { return mergeCustomFieldNodes(accu, cur); }, childNode1);
|
|
1799
|
-
selections_2.push(mergedNode);
|
|
1800
|
-
result = __assign(__assign({}, result), { luvioSelections: selections_2 });
|
|
1801
|
-
sameCustomFields2_2.push.apply(sameCustomFields2_2, sames);
|
|
1802
|
-
return true;
|
|
1803
|
-
}
|
|
1804
|
-
}
|
|
1805
|
-
return false;
|
|
1806
|
-
});
|
|
1807
|
-
sameObjectFields1_2 = node1.luvioSelections
|
|
1808
|
-
.filter(isObjectFieldSelection)
|
|
1809
|
-
.filter(function (childNode1) {
|
|
1810
|
-
if (node2.luvioSelections) {
|
|
1811
|
-
var sames = node2.luvioSelections
|
|
1812
|
-
.filter(isObjectFieldSelection)
|
|
1813
|
-
.filter(function (childNode2) { return childNode2.name === childNode1.name; });
|
|
1814
|
-
if (sames.length > 0) {
|
|
1815
|
-
var mergedNode = sames.reduce(function (accu, cur) { return mergeObjectFieldNodes(accu, cur); }, childNode1);
|
|
1816
|
-
selections_2.push(mergedNode);
|
|
1817
|
-
result = __assign(__assign({}, result), { luvioSelections: selections_2 });
|
|
1818
|
-
sameObjectFields2_2.push.apply(sameObjectFields2_2, sames);
|
|
1819
|
-
return true;
|
|
1820
|
-
}
|
|
1821
|
-
}
|
|
1822
|
-
return false;
|
|
1823
|
-
});
|
|
1824
|
-
sameScalarFields1_2 = node1.luvioSelections
|
|
1825
|
-
.filter(isScalarFieldNode)
|
|
1826
|
-
.filter(function (childNode1) {
|
|
1827
|
-
if (node2.luvioSelections) {
|
|
1828
|
-
var sames = node2.luvioSelections
|
|
1829
|
-
.filter(isScalarFieldNode)
|
|
1830
|
-
.filter(function (childNode2) { return childNode2.name === childNode1.name; });
|
|
1831
|
-
if (sames.length > 0) {
|
|
1832
|
-
var mergedNode = sames.reduce(function (accu, cur) { return mergeScalarFieldNode(accu, cur); }, childNode1);
|
|
1833
|
-
selections_2.push(mergedNode);
|
|
1834
|
-
result = __assign(__assign({}, result), { luvioSelections: selections_2 });
|
|
1835
|
-
sameScalarFields2_2.push.apply(sameScalarFields2_2, sames);
|
|
1836
|
-
return true;
|
|
1837
|
-
}
|
|
1838
|
-
}
|
|
1839
|
-
return false;
|
|
1840
|
-
});
|
|
1841
|
-
if (sameCustomFields1_2.length > 0 ||
|
|
1842
|
-
sameObjectFields1_2.length > 0 ||
|
|
1843
|
-
sameScalarFields1_2.length > 0) {
|
|
1844
|
-
var diffNodes1 = node1.luvioSelections.filter(function (node) {
|
|
1845
|
-
return !sameCustomFields1_2.includes(node) &&
|
|
1846
|
-
!sameObjectFields1_2.includes(node) &&
|
|
1847
|
-
!sameScalarFields1_2.includes(node);
|
|
1848
|
-
});
|
|
1849
|
-
selections_2.push.apply(selections_2, diffNodes1);
|
|
1850
|
-
var diffNodes2 = node2.luvioSelections.filter(function (node) {
|
|
1851
|
-
return !sameCustomFields2_2.includes(node) &&
|
|
1852
|
-
!sameObjectFields2_2.includes(node) &&
|
|
1853
|
-
!sameScalarFields2_2.includes(node);
|
|
1854
|
-
});
|
|
1855
|
-
selections_2.push.apply(selections_2, diffNodes2);
|
|
1856
|
-
result = __assign(__assign({}, result), { luvioSelections: selections_2 });
|
|
1857
|
-
}
|
|
1858
|
-
else {
|
|
1859
|
-
selections_2.push.apply(selections_2, node1.luvioSelections);
|
|
1860
|
-
selections_2.push.apply(selections_2, node2.luvioSelections);
|
|
1861
|
-
result = __assign(__assign({}, result), { luvioSelections: selections_2 });
|
|
1862
|
-
}
|
|
1863
|
-
}
|
|
1864
|
-
else {
|
|
1865
|
-
if (node1.luvioSelections) {
|
|
1866
|
-
return node1;
|
|
1867
|
-
}
|
|
1868
|
-
if (node2.luvioSelections) {
|
|
1869
|
-
return node2;
|
|
1870
|
-
}
|
|
1871
|
-
}
|
|
1872
|
-
return result;
|
|
1873
|
-
}
|
|
1874
|
-
else {
|
|
1875
|
-
// eslint-disable-next-line
|
|
1876
|
-
throw new Error('The fields name needs to be same to be merged');
|
|
1877
|
-
}
|
|
1878
|
-
}
|
|
1879
|
-
function mergeScalarFieldNode(node1, node2) {
|
|
1880
|
-
if (node1.kind === node1.kind && node1.name === node2.name) {
|
|
1881
|
-
return __assign({}, node1);
|
|
1882
|
-
}
|
|
1883
|
-
// eslint-disable-next-line
|
|
1884
|
-
throw new Error('The fields name needs to be same to be merged');
|
|
1885
|
-
}
|
|
1886
|
-
function findRecordSelections(document) {
|
|
1887
|
-
return document.definitions
|
|
1888
|
-
.filter(isOperationDefinition)
|
|
1889
|
-
.reduce(flatMap(luvioSelections), [])
|
|
1890
|
-
.filter(isObjectFieldSelection)
|
|
1891
|
-
.filter(named('uiapi'))
|
|
1892
|
-
.reduce(flatMap(luvioSelections), [])
|
|
1893
|
-
.filter(isObjectFieldSelection)
|
|
1894
|
-
.filter(named('query'))
|
|
1895
|
-
.reduce(flatMap(luvioSelections), [])
|
|
1896
|
-
.filter(isCustomFieldNode);
|
|
1897
|
-
}
|
|
1898
|
-
function isOperationDefinition(node) {
|
|
1899
|
-
return node.kind === 'OperationDefinition';
|
|
1900
|
-
}
|
|
1901
|
-
function isObjectFieldSelection(node) {
|
|
1902
|
-
return node !== undefined && node.kind === 'ObjectFieldSelection';
|
|
1903
|
-
}
|
|
1904
|
-
function isCustomFieldNode(node) {
|
|
1905
|
-
return node !== undefined && node.kind === 'CustomFieldSelection';
|
|
1906
|
-
}
|
|
1907
|
-
function isScalarFieldNode(node) {
|
|
1908
|
-
return node !== undefined && node.kind === 'ScalarFieldSelection';
|
|
1909
|
-
}
|
|
1910
|
-
function flatMap(transform) {
|
|
1911
|
-
return function (acc, current) {
|
|
1912
|
-
var mapped = transform(current);
|
|
1913
|
-
return acc.concat(mapped);
|
|
1914
|
-
};
|
|
1915
|
-
}
|
|
1916
|
-
function luvioSelections(node) {
|
|
1917
|
-
return node.luvioSelections === undefined ? [] : node.luvioSelections;
|
|
1918
|
-
}
|
|
1919
|
-
function named(name) {
|
|
1920
|
-
return function (node) { return node.name === name; };
|
|
1921
|
-
}
|
|
1922
|
-
|
|
1923
|
-
var adapterName = 'graphQL';
|
|
1924
|
-
var RECORD_REPRESENTATION_NAME = 'RecordRepresentation';
|
|
1925
|
-
var GRAPHQL_ROOT_KEY = "".concat(namespace, "::").concat(representationName);
|
|
1926
|
-
function buildSnapshotRefresh(luvio, config, fragment) {
|
|
1927
|
-
return {
|
|
1928
|
-
config: config,
|
|
1929
|
-
resolve: function () { return buildNetworkSnapshot(luvio, config, fragment); },
|
|
1930
|
-
};
|
|
1931
|
-
}
|
|
1932
|
-
function createFragment(luvio, query, variables) {
|
|
1933
|
-
return {
|
|
1934
|
-
kind: 'Fragment',
|
|
1935
|
-
synthetic: false,
|
|
1936
|
-
reader: true,
|
|
1937
|
-
version: GRAPHQL_INGEST_VERSION,
|
|
1938
|
-
read: createRead(luvio, query, variables),
|
|
1939
|
-
};
|
|
1940
|
-
}
|
|
1941
|
-
function onFetchResponseSuccess(luvio, config, response, fragment) {
|
|
1942
|
-
var query = config.query, variables = config.variables;
|
|
1943
|
-
var body = response.body;
|
|
1944
|
-
if (body.errors && body.errors.length > 0) {
|
|
1945
|
-
return Promise.resolve(luvio.storeLookup({
|
|
1946
|
-
recordId: representationName,
|
|
1947
|
-
node: {
|
|
1948
|
-
kind: 'Fragment',
|
|
1949
|
-
synthetic: true,
|
|
1950
|
-
reader: true,
|
|
1951
|
-
read: function (reader) {
|
|
1952
|
-
var sink = {};
|
|
1953
|
-
reader.enterPath('data');
|
|
1954
|
-
reader.assignNonScalar(sink, 'data', body.data);
|
|
1955
|
-
reader.exitPath();
|
|
1956
|
-
reader.enterPath('errors');
|
|
1957
|
-
reader.assignNonScalar(sink, 'errors', deepFreeze(body.errors));
|
|
1958
|
-
reader.exitPath();
|
|
1959
|
-
return sink;
|
|
1960
|
-
},
|
|
1961
|
-
},
|
|
1962
|
-
variables: {},
|
|
1963
|
-
}));
|
|
1964
|
-
}
|
|
1965
|
-
var ingest = createIngest(query, variables);
|
|
1966
|
-
luvio.storeIngest(GRAPHQL_ROOT_KEY, ingest, body.data);
|
|
1967
|
-
var snapshot = luvio.storeLookup({
|
|
1968
|
-
recordId: GRAPHQL_ROOT_KEY,
|
|
1969
|
-
node: fragment,
|
|
1970
|
-
variables: {},
|
|
1971
|
-
}, buildSnapshotRefresh(luvio, config, fragment));
|
|
1972
|
-
return luvio.storeBroadcast().then(function () { return snapshot; });
|
|
1973
|
-
}
|
|
1974
|
-
function getResponseCacheKeys(luvio, config, response, fragment) {
|
|
1975
|
-
// TODO [W-10147827]: make this more efficient
|
|
1976
|
-
// for now we will get the cache keys by actually ingesting then looking at
|
|
1977
|
-
// the seenRecords + recordId
|
|
1978
|
-
var query = config.query, variables = config.variables;
|
|
1979
|
-
var body = response.body;
|
|
1980
|
-
if (body.errors && body.errors.length > 0) {
|
|
1981
|
-
return new engine.StoreKeyMap();
|
|
1982
|
-
}
|
|
1983
|
-
var ingest = createIngest(query, variables);
|
|
1984
|
-
// ingest mutates the response so we have to make a copy
|
|
1985
|
-
var dataCopy = parse(stringify(body.data));
|
|
1986
|
-
luvio.storeIngest(GRAPHQL_ROOT_KEY, ingest, dataCopy);
|
|
1987
|
-
var snapshot = luvio.storeLookup({
|
|
1988
|
-
recordId: GRAPHQL_ROOT_KEY,
|
|
1989
|
-
node: fragment,
|
|
1990
|
-
variables: {},
|
|
1991
|
-
}, buildSnapshotRefresh(luvio, config, fragment));
|
|
1992
|
-
if (snapshot.state === 'Error') {
|
|
1993
|
-
return new engine.StoreKeyMap();
|
|
1994
|
-
}
|
|
1995
|
-
var keys = __spreadArray(__spreadArray([], snapshot.seenRecords.keysAsArray(), true), [snapshot.recordId], false);
|
|
1996
|
-
var keySet = new engine.StoreKeyMap();
|
|
1997
|
-
for (var i = 0, len = keys.length; i < len; i++) {
|
|
1998
|
-
var key = keys[i];
|
|
1999
|
-
var keyNamespace = key.split('::')[0];
|
|
2000
|
-
var representationName_1 = key.split('::')[1].split(':')[0];
|
|
2001
|
-
keySet.set(key, {
|
|
2002
|
-
namespace: keyNamespace,
|
|
2003
|
-
representationName: representationName_1,
|
|
2004
|
-
mergeable: keyNamespace === namespace || representationName_1 === RECORD_REPRESENTATION_NAME,
|
|
2005
|
-
});
|
|
2006
|
-
}
|
|
2007
|
-
return keySet;
|
|
2008
|
-
}
|
|
2009
|
-
function onFetchResponseError(luvio, config, response) {
|
|
2010
|
-
var errorSnapshot = luvio.errorSnapshot(response);
|
|
2011
|
-
luvio.storeIngestError(GRAPHQL_ROOT_KEY, errorSnapshot);
|
|
2012
|
-
return luvio.storeBroadcast().then(function () { return errorSnapshot; });
|
|
2013
|
-
}
|
|
2014
|
-
function buildNetworkSnapshot(luvio, config, fragment, options) {
|
|
2015
|
-
var queryVariables = config.variables, query = config.query;
|
|
2016
|
-
var request = {
|
|
2017
|
-
baseUri: '/services/data/v58.0',
|
|
2018
|
-
basePath: '/graphql',
|
|
2019
|
-
method: 'post',
|
|
2020
|
-
priority: 'normal',
|
|
2021
|
-
body: {
|
|
2022
|
-
query: astToString(query),
|
|
2023
|
-
variables: queryVariables,
|
|
2024
|
-
},
|
|
2025
|
-
queryParams: {},
|
|
2026
|
-
urlParams: {},
|
|
2027
|
-
headers: {},
|
|
2028
|
-
};
|
|
2029
|
-
return luvio.dispatchResourceRequest(request, options).then(function (resp) {
|
|
2030
|
-
return luvio.handleSuccessResponse(function () { return onFetchResponseSuccess(luvio, config, resp, fragment); }, function () { return getResponseCacheKeys(luvio, config, resp, fragment); });
|
|
2031
|
-
}, function (errorResponse) {
|
|
2032
|
-
return luvio.handleErrorResponse(function () {
|
|
2033
|
-
return onFetchResponseError(luvio, config, errorResponse);
|
|
2034
|
-
});
|
|
2035
|
-
});
|
|
2036
|
-
}
|
|
2037
|
-
function validateGraphQlConfig(untrustedConfig) {
|
|
2038
|
-
if (!untrustedIsObject(untrustedConfig)) {
|
|
2039
|
-
return {
|
|
2040
|
-
validatedConfig: null,
|
|
2041
|
-
errors: ["Invalid Config provided isn't an object"],
|
|
2042
|
-
};
|
|
2043
|
-
}
|
|
2044
|
-
if (!('variables' in untrustedConfig && 'query' in untrustedConfig)) {
|
|
2045
|
-
return {
|
|
2046
|
-
validatedConfig: null,
|
|
2047
|
-
errors: [
|
|
2048
|
-
'Missing one or both of the required config parameters "query" and "variables"',
|
|
2049
|
-
],
|
|
2050
|
-
};
|
|
2051
|
-
}
|
|
2052
|
-
var _a = untrustedConfig, variables = _a.variables, query = _a.query;
|
|
2053
|
-
var validationErrors = [];
|
|
2054
|
-
if (isLuvioDocumentNode(query) === false) {
|
|
2055
|
-
validationErrors.push('The config parameter "query" isn\'t a valid LuvioDocumentNode');
|
|
2056
|
-
}
|
|
2057
|
-
var ast = query;
|
|
2058
|
-
if (isGraphQLVariables(variables) === false) {
|
|
2059
|
-
validationErrors.push('The config parameter "variables" isn\'t an object');
|
|
2060
|
-
}
|
|
2061
|
-
if (validationErrors.length > 0) {
|
|
2062
|
-
return {
|
|
2063
|
-
validatedConfig: null,
|
|
2064
|
-
errors: validationErrors,
|
|
2065
|
-
};
|
|
2066
|
-
}
|
|
2067
|
-
validationErrors.push.apply(validationErrors, validate(ast, variables));
|
|
2068
|
-
var useUiApiAdapter = untrustedConfig.useUiApiAdapter;
|
|
2069
|
-
if (useUiApiAdapter !== undefined && typeof useUiApiAdapter !== 'boolean') {
|
|
2070
|
-
validationErrors.push('The config parameter "useUiApiAdapter" isn\'t a boolean');
|
|
2071
|
-
}
|
|
2072
|
-
if (validationErrors.length > 0) {
|
|
2073
|
-
return {
|
|
2074
|
-
validatedConfig: null,
|
|
2075
|
-
errors: validationErrors,
|
|
2076
|
-
};
|
|
2077
|
-
}
|
|
2078
|
-
return {
|
|
2079
|
-
validatedConfig: {
|
|
2080
|
-
variables: variables,
|
|
2081
|
-
query: query,
|
|
2082
|
-
useUiApiAdapter: useUiApiAdapter,
|
|
2083
|
-
},
|
|
2084
|
-
errors: [],
|
|
2085
|
-
};
|
|
2086
|
-
}
|
|
2087
|
-
function buildCachedSnapshot(context, storeLookup) {
|
|
2088
|
-
return buildInMemorySnapshot(context, storeLookup);
|
|
2089
|
-
}
|
|
2090
|
-
function buildInMemorySnapshot(context, storeLookup) {
|
|
2091
|
-
var config = context.config, fragment = context.fragment, luvio = context.luvio;
|
|
2092
|
-
var selector = {
|
|
2093
|
-
recordId: GRAPHQL_ROOT_KEY,
|
|
2094
|
-
node: fragment,
|
|
2095
|
-
variables: {},
|
|
2096
|
-
};
|
|
2097
|
-
return storeLookup(selector, buildSnapshotRefresh(luvio, config, fragment));
|
|
2098
|
-
}
|
|
2099
|
-
function buildNetworkSnapshotCachePolicy(context, coercedAdapterRequestContext) {
|
|
2100
|
-
var config = context.config, fragment = context.fragment, luvio = context.luvio;
|
|
2101
|
-
var networkPriority = coercedAdapterRequestContext.networkPriority, requestCorrelator = coercedAdapterRequestContext.requestCorrelator, eventObservers = coercedAdapterRequestContext.eventObservers;
|
|
2102
|
-
var dispatchOptions = {
|
|
2103
|
-
resourceRequestContext: {
|
|
2104
|
-
requestCorrelator: requestCorrelator,
|
|
2105
|
-
},
|
|
2106
|
-
eventObservers: eventObservers,
|
|
2107
|
-
};
|
|
2108
|
-
if (networkPriority !== 'normal') {
|
|
2109
|
-
dispatchOptions.overrides = {
|
|
2110
|
-
priority: networkPriority,
|
|
2111
|
-
};
|
|
2112
|
-
}
|
|
2113
|
-
return buildNetworkSnapshot(luvio, config, fragment, dispatchOptions);
|
|
2114
|
-
}
|
|
2115
|
-
var graphQLAdapterFactory = function (luvio) {
|
|
2116
|
-
var uiApiGraphQLAdapter = graphql.graphqlAdapterFactory(luvio);
|
|
2117
|
-
function graphql$1(untrustedConfig, requestContext) {
|
|
2118
|
-
var _a = validateGraphQlConfig(untrustedConfig), validatedConfig = _a.validatedConfig, errors = _a.errors;
|
|
2119
|
-
if (errors.length > 0 || validatedConfig === null) {
|
|
2120
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
2121
|
-
throw new Error(errors.join(', '));
|
|
2122
|
-
}
|
|
2123
|
-
return null;
|
|
2124
|
-
}
|
|
2125
|
-
var query = validatedConfig.query, variables = validatedConfig.variables, useUiApiAdapter = validatedConfig.useUiApiAdapter;
|
|
2126
|
-
if (useUiApiAdapter === undefined || useUiApiAdapter === true) {
|
|
2127
|
-
// Forward to new adapters
|
|
2128
|
-
var resolvedQuery = graphqlParser.astResolver(query);
|
|
2129
|
-
if (resolvedQuery === undefined) {
|
|
2130
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
2131
|
-
throw new Error('Could not resolve standard AST');
|
|
2132
|
-
}
|
|
2133
|
-
return null;
|
|
2134
|
-
}
|
|
2135
|
-
return uiApiGraphQLAdapter({
|
|
2136
|
-
query: resolvedQuery,
|
|
2137
|
-
variables: variables,
|
|
2138
|
-
}, requestContext);
|
|
2139
|
-
}
|
|
2140
|
-
else {
|
|
2141
|
-
var fieldInjectionRequired = shouldInjectFields(query);
|
|
2142
|
-
var validatedConfigWithInjection = fieldInjectionRequired
|
|
2143
|
-
? graphqlConfigWithInjectedAST(validatedConfig)
|
|
2144
|
-
: validatedConfig;
|
|
2145
|
-
var fragment = createFragment(luvio, validatedConfigWithInjection.query, variables);
|
|
2146
|
-
var context = {
|
|
2147
|
-
config: validatedConfigWithInjection,
|
|
2148
|
-
fragment: fragment,
|
|
2149
|
-
luvio: luvio,
|
|
2150
|
-
};
|
|
2151
|
-
var snapshotOrPromiseFromCachePolicy = luvio.applyCachePolicy(requestContext || {}, context, buildCachedSnapshot, buildNetworkSnapshotCachePolicy);
|
|
2152
|
-
if (storeEval !== undefined) {
|
|
2153
|
-
var observers = requestContext && requestContext.eventObservers
|
|
2154
|
-
? requestContext.eventObservers
|
|
2155
|
-
: [];
|
|
2156
|
-
// uses the original ast to do the eval to avoid fields not needed by users
|
|
2157
|
-
return storeEval(validatedConfig, snapshotOrPromiseFromCachePolicy, observers);
|
|
2158
|
-
}
|
|
2159
|
-
return snapshotOrPromiseFromCachePolicy;
|
|
2160
|
-
}
|
|
2161
|
-
}
|
|
2162
|
-
return graphql$1;
|
|
2163
|
-
};
|
|
2164
|
-
function graphqlConfigWithInjectedAST(graphqlConfig) {
|
|
2165
|
-
var query = graphqlConfig.query;
|
|
2166
|
-
var astCopy = parse(stringify(query));
|
|
2167
|
-
var modifiedAST = injectFieldsGQL(astCopy);
|
|
2168
|
-
return __assign(__assign({}, graphqlConfig), { query: modifiedAST });
|
|
2169
|
-
}
|
|
2170
|
-
// make sure to register the configuration whenever this module loads
|
|
2171
|
-
ldsDefaultLuvio.register({ id: '@salesforce/lds-adapters-graphql', configuration: configuration });
|
|
2172
|
-
|
|
2173
|
-
exports.adapterName = adapterName;
|
|
2174
|
-
exports.buildCachedSnapshot = buildCachedSnapshot;
|
|
2175
|
-
exports.connectionKeyBuilder = keyBuilder;
|
|
2176
|
-
exports.graphQLAdapterFactory = graphQLAdapterFactory;
|
|
2177
|
-
exports.namespace = namespace;
|
|
2178
|
-
exports.representationName = representationName;
|
|
2179
|
-
|
|
2180
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2181
|
-
|
|
2182
|
-
}));
|