@salesforce/lds-adapters-graphql 1.130.9 → 1.131.0-dev10
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.
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
import { StoreKeyMap } from '@luvio/engine';
|
|
8
8
|
import { register } from '@salesforce/lds-default-luvio';
|
|
9
|
-
import { astResolver } from '@luvio/graphql-parser';
|
|
9
|
+
import { Kind, astResolver } from '@luvio/graphql-parser';
|
|
10
10
|
import { graphqlAdapterFactory } from '@salesforce/lds-adapters-uiapi';
|
|
11
11
|
import { createIngestRecordWithFields, keyBuilderRecord } from '@salesforce/lds-adapters-uiapi';
|
|
12
12
|
|
|
@@ -1422,10 +1422,14 @@ function validate(ast, variables) {
|
|
|
1422
1422
|
}
|
|
1423
1423
|
|
|
1424
1424
|
let storeEval = undefined;
|
|
1425
|
+
let draftFunctions = undefined;
|
|
1425
1426
|
const configuration = {
|
|
1426
1427
|
setStoreEval: function (storeEvalArg) {
|
|
1427
1428
|
storeEval = storeEvalArg;
|
|
1428
1429
|
},
|
|
1430
|
+
setDraftFunctions: function (draftFuncs) {
|
|
1431
|
+
draftFunctions = draftFuncs;
|
|
1432
|
+
},
|
|
1429
1433
|
};
|
|
1430
1434
|
|
|
1431
1435
|
const assignedToMe = {
|
|
@@ -1511,6 +1515,78 @@ function shouldInjectFields(ast) {
|
|
|
1511
1515
|
function injectFieldsGQL(ast) {
|
|
1512
1516
|
return injectScopeFields(ast);
|
|
1513
1517
|
}
|
|
1518
|
+
function swapIdsOfDocumentNode(documentnode, draftFunctions) {
|
|
1519
|
+
const recordNodes = findRecordSelections(documentnode);
|
|
1520
|
+
recordNodes.forEach((recordConnection) => {
|
|
1521
|
+
swapIdsOfFieldNode(recordConnection, draftFunctions);
|
|
1522
|
+
});
|
|
1523
|
+
return documentnode;
|
|
1524
|
+
}
|
|
1525
|
+
function swapIdsOfFieldNode(selectionNode, draftFunctions) {
|
|
1526
|
+
if (isCustomFieldNode(selectionNode) &&
|
|
1527
|
+
selectionNode.type === 'Connection' &&
|
|
1528
|
+
selectionNode.arguments !== undefined &&
|
|
1529
|
+
selectionNode.arguments.some((argment) => argment.name === 'where')) {
|
|
1530
|
+
const swappedArguments = selectionNode.arguments.map((argument) => {
|
|
1531
|
+
if (argument.name === 'where') {
|
|
1532
|
+
return {
|
|
1533
|
+
...argument,
|
|
1534
|
+
value: swapIdsOfValueNode(argument.value, draftFunctions.isDraftId, draftFunctions.getCanonicalId),
|
|
1535
|
+
};
|
|
1536
|
+
}
|
|
1537
|
+
else {
|
|
1538
|
+
return argument;
|
|
1539
|
+
}
|
|
1540
|
+
});
|
|
1541
|
+
selectionNode.arguments = swappedArguments;
|
|
1542
|
+
}
|
|
1543
|
+
if (selectionNode.luvioSelections !== undefined) {
|
|
1544
|
+
for (const childSelectionNode of selectionNode.luvioSelections) {
|
|
1545
|
+
if (isCustomFieldNode(childSelectionNode) ||
|
|
1546
|
+
isObjectFieldSelection(childSelectionNode)) {
|
|
1547
|
+
swapIdsOfFieldNode(childSelectionNode, draftFunctions);
|
|
1548
|
+
}
|
|
1549
|
+
}
|
|
1550
|
+
}
|
|
1551
|
+
}
|
|
1552
|
+
function swapIdsOfValueNode(valueNode, isDraftId, idMapper) {
|
|
1553
|
+
switch (valueNode.kind) {
|
|
1554
|
+
case Kind.OBJECT: {
|
|
1555
|
+
const swappedObjectValueNode = {};
|
|
1556
|
+
for (const key of keys(valueNode.fields)) {
|
|
1557
|
+
swappedObjectValueNode[key] = swapIdsOfValueNode(valueNode.fields[key], isDraftId, idMapper);
|
|
1558
|
+
}
|
|
1559
|
+
return {
|
|
1560
|
+
kind: 'ObjectValue',
|
|
1561
|
+
fields: swappedObjectValueNode,
|
|
1562
|
+
};
|
|
1563
|
+
}
|
|
1564
|
+
case Kind.LIST: {
|
|
1565
|
+
const listValueNodes = [];
|
|
1566
|
+
for (const child of valueNode.values) {
|
|
1567
|
+
listValueNodes.push(swapIdsOfValueNode(child, isDraftId, idMapper));
|
|
1568
|
+
}
|
|
1569
|
+
return {
|
|
1570
|
+
kind: 'ListValue',
|
|
1571
|
+
values: listValueNodes,
|
|
1572
|
+
};
|
|
1573
|
+
}
|
|
1574
|
+
case Kind.STRING: {
|
|
1575
|
+
if (!isDraftId(valueNode.value)) {
|
|
1576
|
+
return valueNode;
|
|
1577
|
+
}
|
|
1578
|
+
return {
|
|
1579
|
+
kind: 'StringValue',
|
|
1580
|
+
value: idMapper(valueNode.value),
|
|
1581
|
+
block: false,
|
|
1582
|
+
};
|
|
1583
|
+
}
|
|
1584
|
+
default:
|
|
1585
|
+
return {
|
|
1586
|
+
...valueNode,
|
|
1587
|
+
};
|
|
1588
|
+
}
|
|
1589
|
+
}
|
|
1514
1590
|
function injectScopeFields(ast) {
|
|
1515
1591
|
const modifiedDocumentNode = {
|
|
1516
1592
|
kind: 'Document',
|
|
@@ -2091,6 +2167,34 @@ function buildNetworkSnapshotCachePolicy(context, coercedAdapterRequestContext)
|
|
|
2091
2167
|
}
|
|
2092
2168
|
return buildNetworkSnapshot(luvio, config, fragment, dispatchOptions);
|
|
2093
2169
|
}
|
|
2170
|
+
const replaceDraftIdsInVariables = (variables, draftFunctions) => {
|
|
2171
|
+
const replace = (object) => {
|
|
2172
|
+
if (typeof object === 'string') {
|
|
2173
|
+
if (!draftFunctions.isDraftId(object)) {
|
|
2174
|
+
return object;
|
|
2175
|
+
}
|
|
2176
|
+
return draftFunctions.getCanonicalId(object);
|
|
2177
|
+
}
|
|
2178
|
+
else if (isArray(object)) {
|
|
2179
|
+
return object.map(replace);
|
|
2180
|
+
}
|
|
2181
|
+
else if (typeof object === 'object' && object !== null) {
|
|
2182
|
+
let source = object;
|
|
2183
|
+
return keys(source).reduce((acc, key) => {
|
|
2184
|
+
acc[key] = replace(source[key]);
|
|
2185
|
+
return acc;
|
|
2186
|
+
}, {});
|
|
2187
|
+
}
|
|
2188
|
+
else {
|
|
2189
|
+
return object;
|
|
2190
|
+
}
|
|
2191
|
+
};
|
|
2192
|
+
let newVariables = keys(variables).reduce((acc, key) => {
|
|
2193
|
+
acc[key] = replace(variables[key]);
|
|
2194
|
+
return acc;
|
|
2195
|
+
}, {});
|
|
2196
|
+
return newVariables;
|
|
2197
|
+
};
|
|
2094
2198
|
const graphQLAdapterFactory = (luvio) => {
|
|
2095
2199
|
const uiApiGraphQLAdapter = graphqlAdapterFactory(luvio);
|
|
2096
2200
|
function graphql(untrustedConfig, requestContext) {
|
|
@@ -2121,19 +2225,33 @@ const graphQLAdapterFactory = (luvio) => {
|
|
|
2121
2225
|
const validatedConfigWithInjection = fieldInjectionRequired
|
|
2122
2226
|
? graphqlConfigWithInjectedAST(validatedConfig)
|
|
2123
2227
|
: validatedConfig;
|
|
2124
|
-
const
|
|
2228
|
+
const sanitizedConfig = draftFunctions !== undefined
|
|
2229
|
+
? sanitizeConfig(validatedConfigWithInjection, draftFunctions)
|
|
2230
|
+
: validatedConfigWithInjection;
|
|
2231
|
+
if (sanitizedConfig.variables && draftFunctions !== undefined) {
|
|
2232
|
+
const variablesWithSwappedDraftIds = replaceDraftIdsInVariables(sanitizedConfig.variables, draftFunctions);
|
|
2233
|
+
sanitizedConfig.variables = variablesWithSwappedDraftIds;
|
|
2234
|
+
validatedConfig.variables = variablesWithSwappedDraftIds;
|
|
2235
|
+
}
|
|
2236
|
+
const fragment = createFragment(luvio, sanitizedConfig.query, sanitizedConfig.variables);
|
|
2125
2237
|
const context = {
|
|
2126
|
-
config:
|
|
2238
|
+
config: sanitizedConfig,
|
|
2127
2239
|
fragment,
|
|
2128
2240
|
luvio,
|
|
2129
2241
|
};
|
|
2242
|
+
// NOTE: For evaluating environments, set a context property to let the
|
|
2243
|
+
// environment detect that eval will happen and to check varous gates
|
|
2244
|
+
// for eval behavior customizations.
|
|
2245
|
+
if (storeEval !== undefined) {
|
|
2246
|
+
context.gqlEval = true;
|
|
2247
|
+
}
|
|
2130
2248
|
const snapshotOrPromiseFromCachePolicy = luvio.applyCachePolicy(requestContext || {}, context, buildCachedSnapshot, buildNetworkSnapshotCachePolicy);
|
|
2131
2249
|
if (storeEval !== undefined) {
|
|
2132
2250
|
const observers = requestContext && requestContext.eventObservers
|
|
2133
2251
|
? requestContext.eventObservers
|
|
2134
2252
|
: [];
|
|
2135
|
-
// uses the original ast to do the eval to avoid fields not needed by users
|
|
2136
|
-
return storeEval(validatedConfig, snapshotOrPromiseFromCachePolicy, observers);
|
|
2253
|
+
// uses the original ast to do the eval to avoid fields not needed by users. The draftID swapping happens when filters transform to predicates.
|
|
2254
|
+
return storeEval(validatedConfig, snapshotOrPromiseFromCachePolicy, observers, keyBuilder);
|
|
2137
2255
|
}
|
|
2138
2256
|
return snapshotOrPromiseFromCachePolicy;
|
|
2139
2257
|
}
|
|
@@ -2149,7 +2267,16 @@ function graphqlConfigWithInjectedAST(graphqlConfig) {
|
|
|
2149
2267
|
query: modifiedAST,
|
|
2150
2268
|
};
|
|
2151
2269
|
}
|
|
2270
|
+
function sanitizeConfig(graphqlConfig, draftFunctions) {
|
|
2271
|
+
const { query } = graphqlConfig;
|
|
2272
|
+
const astCopy = parse(stringify(query));
|
|
2273
|
+
const modifiedAST = swapIdsOfDocumentNode(astCopy, draftFunctions);
|
|
2274
|
+
return {
|
|
2275
|
+
...graphqlConfig,
|
|
2276
|
+
query: modifiedAST,
|
|
2277
|
+
};
|
|
2278
|
+
}
|
|
2152
2279
|
// make sure to register the configuration whenever this module loads
|
|
2153
2280
|
register({ id: '@salesforce/lds-adapters-graphql', configuration });
|
|
2154
2281
|
|
|
2155
|
-
export { adapterName, buildCachedSnapshot, keyBuilder as connectionKeyBuilder, graphQLAdapterFactory, namespace, representationName };
|
|
2282
|
+
export { adapterName, buildCachedSnapshot, keyBuilder as connectionKeyBuilder, graphQLAdapterFactory, graphqlConfigWithInjectedAST, namespace, replaceDraftIdsInVariables, representationName, sanitizeConfig };
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import type { StoreEval } from '@salesforce/lds-graphql-eval';
|
|
1
|
+
import type { StoreEval, DraftFunctions } from '@salesforce/lds-graphql-eval';
|
|
2
2
|
export declare let storeEval: StoreEval<unknown> | undefined;
|
|
3
|
+
export declare let draftFunctions: DraftFunctions | undefined;
|
|
3
4
|
export declare const configuration: {
|
|
4
5
|
setStoreEval: (storeEvalArg: typeof storeEval) => void;
|
|
6
|
+
setDraftFunctions: (draftFuncs: typeof draftFunctions) => void;
|
|
5
7
|
};
|
|
6
8
|
export type Registration = {
|
|
7
9
|
id: '@salesforce/lds-adapters-graphql';
|
|
@@ -2,6 +2,9 @@ import type { AdapterFactory, Luvio, ReaderFragment, Snapshot, StoreLookup } fro
|
|
|
2
2
|
import type { LuvioDocumentNode } from '@luvio/graphql-parser';
|
|
3
3
|
import type { GraphQLVariables } from './type/Variable';
|
|
4
4
|
import type { Registration } from './configuration';
|
|
5
|
+
import type { DraftFunctions } from '@salesforce/lds-graphql-eval';
|
|
6
|
+
import { keyBuilder as connectionKeyBuilder } from './custom/connection';
|
|
7
|
+
export { connectionKeyBuilder };
|
|
5
8
|
export { namespace, representationName } from './util/adapter';
|
|
6
9
|
export declare const adapterName = "graphQL";
|
|
7
10
|
interface GraphQLConfig {
|
|
@@ -13,8 +16,11 @@ type BuildSnapshotContext = {
|
|
|
13
16
|
config: GraphQLConfig;
|
|
14
17
|
fragment: ReaderFragment;
|
|
15
18
|
luvio: Luvio;
|
|
19
|
+
gqlEval?: boolean;
|
|
16
20
|
};
|
|
17
21
|
export declare function buildCachedSnapshot(context: BuildSnapshotContext, storeLookup: StoreLookup<unknown>): Promise<Snapshot<unknown, unknown>> | Snapshot<unknown, any>;
|
|
22
|
+
export declare const replaceDraftIdsInVariables: (variables: Record<string, any>, draftFunctions: DraftFunctions) => Record<string, any>;
|
|
18
23
|
export declare const graphQLAdapterFactory: AdapterFactory<GraphQLConfig, unknown>;
|
|
24
|
+
export declare function graphqlConfigWithInjectedAST(graphqlConfig: GraphQLConfig): GraphQLConfig;
|
|
25
|
+
export declare function sanitizeConfig(graphqlConfig: GraphQLConfig, draftFunctions: DraftFunctions): GraphQLConfig;
|
|
19
26
|
export type { Registration };
|
|
20
|
-
export { keyBuilder as connectionKeyBuilder } from './custom/connection';
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import type { LuvioDocumentNode, LuvioSelectionNode, LuvioSelectionObjectFieldNode, LuvioSelectionScalarFieldNode, LuvioSelectionCustomFieldNode, LuvioDefinitionNode, LuvioOperationDefinitionNode } from '@luvio/graphql-parser';
|
|
2
|
+
import type { DraftFunctions } from '@salesforce/lds-graphql-eval';
|
|
2
3
|
export declare function shouldInjectFields(ast: LuvioDocumentNode): boolean;
|
|
3
4
|
export declare function injectFieldsGQL(ast: LuvioDocumentNode): LuvioDocumentNode;
|
|
5
|
+
export declare function swapIdsOfDocumentNode(documentnode: LuvioDocumentNode, draftFunctions: DraftFunctions): LuvioDocumentNode;
|
|
6
|
+
export declare function mergeSelectionNodes(group1: LuvioSelectionNode[], group2: LuvioSelectionNode[]): LuvioSelectionNode[];
|
|
4
7
|
export declare function findRecordSelections(document: LuvioDocumentNode): LuvioSelectionCustomFieldNode[];
|
|
5
8
|
export declare function isOperationDefinition(node: LuvioDefinitionNode): node is LuvioOperationDefinitionNode;
|
|
6
9
|
export declare function isObjectFieldSelection(node: LuvioSelectionNode | undefined): node is LuvioSelectionObjectFieldNode;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salesforce/lds-adapters-graphql",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.131.0-dev10",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
5
5
|
"description": "Wire adapter for GraphQL API endpoint",
|
|
6
6
|
"main": "dist/es/es2018/graphql-service.js",
|
|
@@ -37,15 +37,15 @@
|
|
|
37
37
|
"release:core": "../../scripts/release/core.js --adapter=lds-adapters-graphql"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@luvio/graphql-parser": "0.138.8",
|
|
41
|
-
"@salesforce/lds-adapters-uiapi": "
|
|
42
|
-
"@salesforce/lds-bindings": "
|
|
43
|
-
"@salesforce/lds-default-luvio": "
|
|
40
|
+
"@luvio/graphql-parser": "0.138.8-244.1",
|
|
41
|
+
"@salesforce/lds-adapters-uiapi": "1.131.0-dev10",
|
|
42
|
+
"@salesforce/lds-bindings": "1.131.0-dev10",
|
|
43
|
+
"@salesforce/lds-default-luvio": "1.131.0-dev10"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@salesforce/lds-compiler-plugins": "
|
|
47
|
-
"@salesforce/lds-graphql-eval": "
|
|
48
|
-
"@salesforce/lds-jest": "
|
|
46
|
+
"@salesforce/lds-compiler-plugins": "1.131.0-dev10",
|
|
47
|
+
"@salesforce/lds-graphql-eval": "1.131.0-dev10",
|
|
48
|
+
"@salesforce/lds-jest": "1.131.0-dev10"
|
|
49
49
|
},
|
|
50
50
|
"nx": {
|
|
51
51
|
"targets": {
|
|
@@ -63,9 +63,9 @@
|
|
|
63
63
|
{
|
|
64
64
|
"path": "./sfdc/index.js",
|
|
65
65
|
"maxSize": {
|
|
66
|
-
"none": "
|
|
67
|
-
"min": "
|
|
68
|
-
"compressed": "
|
|
66
|
+
"none": "86 kB",
|
|
67
|
+
"min": "40 kB",
|
|
68
|
+
"compressed": "13.5 kB"
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
],
|
package/sfdc/index.js
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
import { createLDSAdapter, createWireAdapterConstructor, createInstrumentedAdapter, createImperativeAdapter } from 'force/ldsBindings';
|
|
16
16
|
import { register, withDefaultLuvio } from 'force/ldsEngine';
|
|
17
17
|
import { StoreKeyMap } from 'force/luvioEngine';
|
|
18
|
-
import { astResolver } from 'force/ldsGraphqlParser';
|
|
18
|
+
import { Kind, astResolver } from 'force/ldsGraphqlParser';
|
|
19
19
|
import { graphqlAdapterFactory } from 'force/ldsAdaptersUiapiGraphql';
|
|
20
20
|
import { createIngestRecordWithFields, keyBuilderRecord } from 'force/ldsAdaptersUiapi';
|
|
21
21
|
|
|
@@ -1431,10 +1431,14 @@ function validate(ast, variables) {
|
|
|
1431
1431
|
}
|
|
1432
1432
|
|
|
1433
1433
|
let storeEval = undefined;
|
|
1434
|
+
let draftFunctions = undefined;
|
|
1434
1435
|
const configuration = {
|
|
1435
1436
|
setStoreEval: function (storeEvalArg) {
|
|
1436
1437
|
storeEval = storeEvalArg;
|
|
1437
1438
|
},
|
|
1439
|
+
setDraftFunctions: function (draftFuncs) {
|
|
1440
|
+
draftFunctions = draftFuncs;
|
|
1441
|
+
},
|
|
1438
1442
|
};
|
|
1439
1443
|
|
|
1440
1444
|
const assignedToMe = {
|
|
@@ -1520,6 +1524,78 @@ function shouldInjectFields(ast) {
|
|
|
1520
1524
|
function injectFieldsGQL(ast) {
|
|
1521
1525
|
return injectScopeFields(ast);
|
|
1522
1526
|
}
|
|
1527
|
+
function swapIdsOfDocumentNode(documentnode, draftFunctions) {
|
|
1528
|
+
const recordNodes = findRecordSelections(documentnode);
|
|
1529
|
+
recordNodes.forEach((recordConnection) => {
|
|
1530
|
+
swapIdsOfFieldNode(recordConnection, draftFunctions);
|
|
1531
|
+
});
|
|
1532
|
+
return documentnode;
|
|
1533
|
+
}
|
|
1534
|
+
function swapIdsOfFieldNode(selectionNode, draftFunctions) {
|
|
1535
|
+
if (isCustomFieldNode(selectionNode) &&
|
|
1536
|
+
selectionNode.type === 'Connection' &&
|
|
1537
|
+
selectionNode.arguments !== undefined &&
|
|
1538
|
+
selectionNode.arguments.some((argment) => argment.name === 'where')) {
|
|
1539
|
+
const swappedArguments = selectionNode.arguments.map((argument) => {
|
|
1540
|
+
if (argument.name === 'where') {
|
|
1541
|
+
return {
|
|
1542
|
+
...argument,
|
|
1543
|
+
value: swapIdsOfValueNode(argument.value, draftFunctions.isDraftId, draftFunctions.getCanonicalId),
|
|
1544
|
+
};
|
|
1545
|
+
}
|
|
1546
|
+
else {
|
|
1547
|
+
return argument;
|
|
1548
|
+
}
|
|
1549
|
+
});
|
|
1550
|
+
selectionNode.arguments = swappedArguments;
|
|
1551
|
+
}
|
|
1552
|
+
if (selectionNode.luvioSelections !== undefined) {
|
|
1553
|
+
for (const childSelectionNode of selectionNode.luvioSelections) {
|
|
1554
|
+
if (isCustomFieldNode(childSelectionNode) ||
|
|
1555
|
+
isObjectFieldSelection(childSelectionNode)) {
|
|
1556
|
+
swapIdsOfFieldNode(childSelectionNode, draftFunctions);
|
|
1557
|
+
}
|
|
1558
|
+
}
|
|
1559
|
+
}
|
|
1560
|
+
}
|
|
1561
|
+
function swapIdsOfValueNode(valueNode, isDraftId, idMapper) {
|
|
1562
|
+
switch (valueNode.kind) {
|
|
1563
|
+
case Kind.OBJECT: {
|
|
1564
|
+
const swappedObjectValueNode = {};
|
|
1565
|
+
for (const key of keys(valueNode.fields)) {
|
|
1566
|
+
swappedObjectValueNode[key] = swapIdsOfValueNode(valueNode.fields[key], isDraftId, idMapper);
|
|
1567
|
+
}
|
|
1568
|
+
return {
|
|
1569
|
+
kind: 'ObjectValue',
|
|
1570
|
+
fields: swappedObjectValueNode,
|
|
1571
|
+
};
|
|
1572
|
+
}
|
|
1573
|
+
case Kind.LIST: {
|
|
1574
|
+
const listValueNodes = [];
|
|
1575
|
+
for (const child of valueNode.values) {
|
|
1576
|
+
listValueNodes.push(swapIdsOfValueNode(child, isDraftId, idMapper));
|
|
1577
|
+
}
|
|
1578
|
+
return {
|
|
1579
|
+
kind: 'ListValue',
|
|
1580
|
+
values: listValueNodes,
|
|
1581
|
+
};
|
|
1582
|
+
}
|
|
1583
|
+
case Kind.STRING: {
|
|
1584
|
+
if (!isDraftId(valueNode.value)) {
|
|
1585
|
+
return valueNode;
|
|
1586
|
+
}
|
|
1587
|
+
return {
|
|
1588
|
+
kind: 'StringValue',
|
|
1589
|
+
value: idMapper(valueNode.value),
|
|
1590
|
+
block: false,
|
|
1591
|
+
};
|
|
1592
|
+
}
|
|
1593
|
+
default:
|
|
1594
|
+
return {
|
|
1595
|
+
...valueNode,
|
|
1596
|
+
};
|
|
1597
|
+
}
|
|
1598
|
+
}
|
|
1523
1599
|
function injectScopeFields(ast) {
|
|
1524
1600
|
const modifiedDocumentNode = {
|
|
1525
1601
|
kind: 'Document',
|
|
@@ -2100,6 +2176,34 @@ function buildNetworkSnapshotCachePolicy(context, coercedAdapterRequestContext)
|
|
|
2100
2176
|
}
|
|
2101
2177
|
return buildNetworkSnapshot(luvio, config, fragment, dispatchOptions);
|
|
2102
2178
|
}
|
|
2179
|
+
const replaceDraftIdsInVariables = (variables, draftFunctions) => {
|
|
2180
|
+
const replace = (object) => {
|
|
2181
|
+
if (typeof object === 'string') {
|
|
2182
|
+
if (!draftFunctions.isDraftId(object)) {
|
|
2183
|
+
return object;
|
|
2184
|
+
}
|
|
2185
|
+
return draftFunctions.getCanonicalId(object);
|
|
2186
|
+
}
|
|
2187
|
+
else if (isArray(object)) {
|
|
2188
|
+
return object.map(replace);
|
|
2189
|
+
}
|
|
2190
|
+
else if (typeof object === 'object' && object !== null) {
|
|
2191
|
+
let source = object;
|
|
2192
|
+
return keys(source).reduce((acc, key) => {
|
|
2193
|
+
acc[key] = replace(source[key]);
|
|
2194
|
+
return acc;
|
|
2195
|
+
}, {});
|
|
2196
|
+
}
|
|
2197
|
+
else {
|
|
2198
|
+
return object;
|
|
2199
|
+
}
|
|
2200
|
+
};
|
|
2201
|
+
let newVariables = keys(variables).reduce((acc, key) => {
|
|
2202
|
+
acc[key] = replace(variables[key]);
|
|
2203
|
+
return acc;
|
|
2204
|
+
}, {});
|
|
2205
|
+
return newVariables;
|
|
2206
|
+
};
|
|
2103
2207
|
const graphQLAdapterFactory = (luvio) => {
|
|
2104
2208
|
const uiApiGraphQLAdapter = graphqlAdapterFactory(luvio);
|
|
2105
2209
|
function graphql(untrustedConfig, requestContext) {
|
|
@@ -2130,19 +2234,33 @@ const graphQLAdapterFactory = (luvio) => {
|
|
|
2130
2234
|
const validatedConfigWithInjection = fieldInjectionRequired
|
|
2131
2235
|
? graphqlConfigWithInjectedAST(validatedConfig)
|
|
2132
2236
|
: validatedConfig;
|
|
2133
|
-
const
|
|
2237
|
+
const sanitizedConfig = draftFunctions !== undefined
|
|
2238
|
+
? sanitizeConfig(validatedConfigWithInjection, draftFunctions)
|
|
2239
|
+
: validatedConfigWithInjection;
|
|
2240
|
+
if (sanitizedConfig.variables && draftFunctions !== undefined) {
|
|
2241
|
+
const variablesWithSwappedDraftIds = replaceDraftIdsInVariables(sanitizedConfig.variables, draftFunctions);
|
|
2242
|
+
sanitizedConfig.variables = variablesWithSwappedDraftIds;
|
|
2243
|
+
validatedConfig.variables = variablesWithSwappedDraftIds;
|
|
2244
|
+
}
|
|
2245
|
+
const fragment = createFragment(luvio, sanitizedConfig.query, sanitizedConfig.variables);
|
|
2134
2246
|
const context = {
|
|
2135
|
-
config:
|
|
2247
|
+
config: sanitizedConfig,
|
|
2136
2248
|
fragment,
|
|
2137
2249
|
luvio,
|
|
2138
2250
|
};
|
|
2251
|
+
// NOTE: For evaluating environments, set a context property to let the
|
|
2252
|
+
// environment detect that eval will happen and to check varous gates
|
|
2253
|
+
// for eval behavior customizations.
|
|
2254
|
+
if (storeEval !== undefined) {
|
|
2255
|
+
context.gqlEval = true;
|
|
2256
|
+
}
|
|
2139
2257
|
const snapshotOrPromiseFromCachePolicy = luvio.applyCachePolicy(requestContext || {}, context, buildCachedSnapshot, buildNetworkSnapshotCachePolicy);
|
|
2140
2258
|
if (storeEval !== undefined) {
|
|
2141
2259
|
const observers = requestContext && requestContext.eventObservers
|
|
2142
2260
|
? requestContext.eventObservers
|
|
2143
2261
|
: [];
|
|
2144
|
-
// uses the original ast to do the eval to avoid fields not needed by users
|
|
2145
|
-
return storeEval(validatedConfig, snapshotOrPromiseFromCachePolicy, observers);
|
|
2262
|
+
// uses the original ast to do the eval to avoid fields not needed by users. The draftID swapping happens when filters transform to predicates.
|
|
2263
|
+
return storeEval(validatedConfig, snapshotOrPromiseFromCachePolicy, observers, keyBuilder);
|
|
2146
2264
|
}
|
|
2147
2265
|
return snapshotOrPromiseFromCachePolicy;
|
|
2148
2266
|
}
|
|
@@ -2158,6 +2276,15 @@ function graphqlConfigWithInjectedAST(graphqlConfig) {
|
|
|
2158
2276
|
query: modifiedAST,
|
|
2159
2277
|
};
|
|
2160
2278
|
}
|
|
2279
|
+
function sanitizeConfig(graphqlConfig, draftFunctions) {
|
|
2280
|
+
const { query } = graphqlConfig;
|
|
2281
|
+
const astCopy = parse(stringify(query));
|
|
2282
|
+
const modifiedAST = swapIdsOfDocumentNode(astCopy, draftFunctions);
|
|
2283
|
+
return {
|
|
2284
|
+
...graphqlConfig,
|
|
2285
|
+
query: modifiedAST,
|
|
2286
|
+
};
|
|
2287
|
+
}
|
|
2161
2288
|
// make sure to register the configuration whenever this module loads
|
|
2162
2289
|
register({ id: '@salesforce/lds-adapters-graphql', configuration });
|
|
2163
2290
|
|
|
@@ -2177,4 +2304,4 @@ withDefaultLuvio((luvio) => {
|
|
|
2177
2304
|
});
|
|
2178
2305
|
|
|
2179
2306
|
export { graphQL, graphQLImperative, unstable_graphQL_imperative };
|
|
2180
|
-
// version: 1.
|
|
2307
|
+
// version: 1.131.0-dev10-5a970f64a
|