@salesforce/lds-worker-api 1.229.0-dev1 → 1.229.0-dev3

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.
@@ -3841,7 +3841,7 @@ function createResourceParamsImpl(config, configMetadata) {
3841
3841
  }
3842
3842
  return resourceParams;
3843
3843
  }
3844
- // engine version: 0.145.2-6a13677c
3844
+ // engine version: 0.146.0-dev3-502c4337
3845
3845
 
3846
3846
  /**
3847
3847
  * Copyright (c) 2022, Salesforce, Inc.,
@@ -3968,7 +3968,7 @@ function withDefaultLuvio(callback) {
3968
3968
  }
3969
3969
  callbacks.push(callback);
3970
3970
  }
3971
- // version: 1.229.0-dev1-f69d054a9
3971
+ // version: 1.229.0-dev3-175ac936b
3972
3972
 
3973
3973
  // TODO [TD-0081508]: once that TD is fulfilled we can probably change this file
3974
3974
  function instrumentAdapter$1(createFunction, _metadata) {
@@ -15429,7 +15429,7 @@ function gql(literals, ...subs) {
15429
15429
  }
15430
15430
  return superResult;
15431
15431
  }
15432
- // version: 1.229.0-dev1-f69d054a9
15432
+ // version: 1.229.0-dev3-175ac936b
15433
15433
 
15434
15434
  function unwrap(data) {
15435
15435
  // The lwc-luvio bindings import a function from lwc called "unwrap".
@@ -15530,14 +15530,15 @@ function refreshData(data, dataToTuple, luvio) {
15530
15530
  return undefined;
15531
15531
  });
15532
15532
  }
15533
- const { isArray: isArray$8 } = Array;
15534
- const { stringify: stringify$9 } = JSON;
15535
15533
 
15536
15534
  function isPromise$1(value) {
15537
15535
  // check for Thenable due to test frameworks using custom Promise impls
15538
15536
  return value.then !== undefined;
15539
15537
  }
15540
15538
 
15539
+ const { isArray: isArray$8 } = Array;
15540
+ const { stringify: stringify$9 } = JSON;
15541
+
15541
15542
  /**
15542
15543
  * (Re)throws an error after adding a prefix to the message.
15543
15544
  *
@@ -16352,7 +16353,7 @@ function createGraphQLWireAdapterConstructor(luvio, adapter, metadata, astResolv
16352
16353
  const { apiFamily, name } = metadata;
16353
16354
  return createGraphQLWireAdapterConstructor$1(adapter, `${apiFamily}.${name}`, luvio, astResolver);
16354
16355
  }
16355
- // version: 1.229.0-dev1-f69d054a9
16356
+ // version: 1.229.0-dev3-175ac936b
16356
16357
 
16357
16358
  /**
16358
16359
  * Copyright (c) 2022, Salesforce, Inc.,
@@ -16451,7 +16452,7 @@ var TypeCheckShapes;
16451
16452
  TypeCheckShapes[TypeCheckShapes["Integer"] = 3] = "Integer";
16452
16453
  TypeCheckShapes[TypeCheckShapes["Unsupported"] = 4] = "Unsupported";
16453
16454
  })(TypeCheckShapes || (TypeCheckShapes = {}));
16454
- // engine version: 0.145.2-6a13677c
16455
+ // engine version: 0.146.0-dev3-502c4337
16455
16456
 
16456
16457
  const { keys: ObjectKeys$3, create: ObjectCreate$3 } = Object;
16457
16458
 
@@ -25038,18 +25039,28 @@ const buildLayoutModeCacheSnapshot = (apiName, recordTypeId, layoutType, mode) =
25038
25039
  * These are intermediate lookups to check if the record is in the L2 cache
25039
25040
  * @param {Luvio} luvio
25040
25041
  * @param {GetRecordLayoutTypeConfig} config
25041
- * @param {BuildCachedSnapshot<BuildSnapshotContext} cachedSnapshot
25042
+ * @param {BuildCachedSnapshot<BuildSnapshotContext>} cachedSnapshot
25042
25043
  */
25043
25044
  function makeCacheOnlySnapshot(luvio, config, adapterContext, cachedSnapshot) {
25044
- return luvio.applyCachePolicy({
25045
- cachePolicy: {
25046
- // only looking in the cache so we can check for L2 data offline
25047
- type: 'only-if-cached',
25048
- },
25049
- }, { config, luvio, adapterContext }, cachedSnapshot,
25050
- // this won't be invoked since we're requesting only-if-cached
25045
+ return luvio.applyCachePolicy(
25046
+ // Pass empty context so environment will use its default cache-policy
25047
+ {}, { config, luvio, adapterContext }, cachedSnapshot,
25048
+ // disallow hitting the network by returning a gateway timeout
25051
25049
  () => {
25052
- throw Error('buildNetworkSnapshot should not be called for only-if-cached policy');
25050
+ return new Promise((resolve) => {
25051
+ resolve({
25052
+ state: 'Error',
25053
+ data: undefined,
25054
+ error: {
25055
+ body: undefined,
25056
+ headers: {},
25057
+ ok: false,
25058
+ status: 504,
25059
+ statusText: 'Gateway Timeout',
25060
+ errorType: 'fetchResponse',
25061
+ },
25062
+ });
25063
+ });
25053
25064
  });
25054
25065
  }
25055
25066
  /**
@@ -41158,7 +41169,7 @@ withDefaultLuvio((luvio) => {
41158
41169
  throttle(60, 60000, createLDSAdapter(luvio, 'notifyListInfoUpdateAvailable', notifyUpdateAvailableFactory$1));
41159
41170
  throttle(60, 60000, createLDSAdapter(luvio, 'notifyQuickActionDefaultsUpdateAvailable', notifyUpdateAvailableFactory));
41160
41171
  });
41161
- // version: 1.229.0-dev1-5b6d3db67
41172
+ // version: 1.229.0-dev3-71194d134
41162
41173
 
41163
41174
  var caseSensitiveUserId = '005B0000000GR4OIAW';
41164
41175
 
@@ -41789,6 +41800,9 @@ function handleDurableStoreRejection(instrument) {
41789
41800
  }
41790
41801
 
41791
41802
  function isStoreEntryError(storeRecord) {
41803
+ if (!storeRecord || typeof storeRecord !== 'object') {
41804
+ return false;
41805
+ }
41792
41806
  return storeRecord.__type === 'error';
41793
41807
  }
41794
41808
 
@@ -45497,8 +45511,8 @@ function rootRecordQuery(selection, input) {
45497
45511
  // If there is no metadata for this query or it somehow lacks a timestamp
45498
45512
  // skip setting the root timestamp
45499
45513
  if (queryMetadata !== undefined && queryMetadata.ingestionTimestamp !== undefined) {
45500
- // subtract 10ms from timestamp to account for ingestion processing time
45501
- input.rootTimestamp = queryMetadata.ingestionTimestamp - 10;
45514
+ // subtract 1000ms from timestamp to account for ingestion processing time
45515
+ input.rootTimestamp = queryMetadata.ingestionTimestamp - 1000;
45502
45516
  }
45503
45517
  }
45504
45518
  return recordQuery(selection, alias, apiName, [], input);
@@ -49280,6 +49294,10 @@ function isOperationDefinitionNode(node) {
49280
49294
  return node.kind === 'OperationDefinition';
49281
49295
  }
49282
49296
 
49297
+ const POLYMORPHIC_PARENT_RELATIONSHIP = 'polymorphicParentRelationship';
49298
+ const PARENT_RELATIONSHIP = 'parentRelationship';
49299
+ const CHILD_RELATIONSHIP = 'childRelationship';
49300
+ const RECORD_QUERY = 'recordQuery';
49283
49301
  function requestsDraftsField(recordFieldNode) {
49284
49302
  if (!recordFieldNode.selectionSet)
49285
49303
  return false;
@@ -49295,18 +49313,41 @@ function isRecordQuery(recordQueryField) {
49295
49313
  directive.arguments
49296
49314
  .map((argument) => argument.value)
49297
49315
  .filter(isStringValueNode)
49298
- .some((categoryName) => categoryName.value === 'recordQuery'));
49316
+ .some((categoryName) => categoryName.value === RECORD_QUERY));
49299
49317
  });
49300
49318
  }
49301
49319
  return false;
49302
49320
  }
49303
- // finds field with 'recordQuery' and 'childRelationship' directive
49304
- function findNearestRecordQuery(ancestors) {
49305
- const recordQueryAncester = findNearestAncesterPath(ancestors, true).node;
49306
- return recordQueryAncester === undefined ? undefined : recordQueryAncester;
49321
+ // finds connection field with 'recordQuery' and 'childRelationship' directive.
49322
+ function findNearestConnection(ancestors) {
49323
+ const connectionAncestor = findNearestAncesterPath(ancestors, true).node;
49324
+ return connectionAncestor === undefined ? undefined : connectionAncestor;
49325
+ }
49326
+ // convinient method to find nearest connection with its path
49327
+ function findNearestConnectionWithPath(ancestors) {
49328
+ const closestAncestorPath = findNearestAncesterPath(ancestors, true);
49329
+ let connection = undefined;
49330
+ let connectionPath = undefined;
49331
+ if (closestAncestorPath.parentIndex > 0) {
49332
+ const connectionAncestor = closestAncestorPath.node;
49333
+ const connectionAncestors = ancestors.slice(0, closestAncestorPath.parentIndex);
49334
+ connection =
49335
+ connectionAncestor === undefined ? undefined : connectionAncestor;
49336
+ if (connection !== undefined) {
49337
+ const ancesterPath = findAncesterPath(connectionAncestors);
49338
+ connectionPath =
49339
+ ancesterPath === ''
49340
+ ? connection.name.value
49341
+ : `${ancesterPath}#${connection.name.value}`;
49342
+ }
49343
+ }
49344
+ return {
49345
+ connection,
49346
+ path: connectionPath,
49347
+ };
49307
49348
  }
49308
- // finds cloeset ancester. If 'parentRelationship' is allowed, it could be 'InlineFragmentNode' since it inherits the 'parent' relationship. 'InlineFragmentNode' makes sure that only one 'apiName' returns when tree is traversed.
49309
- function findNearestAncesterPath(ancestors, recordQueryOnly) {
49349
+ // finds closest ancestor. If node with 'parentRelationship' is the ancester, the end result could be 'InlineFragmentNode' since it inherits the 'parent' relationship. 'InlineFragmentNode' makes sure that only one 'apiName' returns when tree is traversed.
49350
+ function findNearestAncesterPath(ancestors, connectionOnly) {
49310
49351
  let recordQueryPath = { node: undefined, parentIndex: -1 };
49311
49352
  let relationship = '';
49312
49353
  for (let i = ancestors.length - 1; i >= 0; i--) {
@@ -49320,9 +49361,11 @@ function findNearestAncesterPath(ancestors, recordQueryOnly) {
49320
49361
  continue;
49321
49362
  for (let arg of directive.arguments) {
49322
49363
  if (arg.value &&
49323
- (arg.value.value === 'recordQuery' ||
49324
- arg.value.value === 'childRelationship' ||
49325
- (!recordQueryOnly && arg.value.value === 'parentRelationship'))) {
49364
+ (arg.value.value === RECORD_QUERY ||
49365
+ arg.value.value === CHILD_RELATIONSHIP ||
49366
+ (!connectionOnly &&
49367
+ (arg.value.value === PARENT_RELATIONSHIP ||
49368
+ arg.value.value === POLYMORPHIC_PARENT_RELATIONSHIP)))) {
49326
49369
  recordQueryPath = { node: node, parentIndex: i };
49327
49370
  relationship = arg.value.value;
49328
49371
  break;
@@ -49337,17 +49380,19 @@ function findNearestAncesterPath(ancestors, recordQueryOnly) {
49337
49380
  //checks if nearest ancester could be an inline fragment
49338
49381
  if (recordQueryPath.node !== undefined &&
49339
49382
  recordQueryPath.node.selectionSet &&
49340
- relationship === 'parentRelationship') {
49341
- //
49342
- if (recordQueryPath.node.selectionSet.selections.every(isInlineFragmentNode)) {
49343
- //
49344
- const inlineFragmentLoc = recordQueryPath.parentIndex + 2;
49345
- if (inlineFragmentLoc < ancestors.length && ancestors[inlineFragmentLoc]) {
49383
+ (relationship === PARENT_RELATIONSHIP || relationship === POLYMORPHIC_PARENT_RELATIONSHIP)) {
49384
+ // InlineFragment is usually 3 steps aways from its FieldNode parent within ancester hierarchy if it exists. The below search
49385
+ // is applied to adapt to future AST structure change
49386
+ let parentIndex = recordQueryPath.parentIndex + 1;
49387
+ while (parentIndex < ancestors.length) {
49388
+ if (isInlineFragmentNode(ancestors[parentIndex])) {
49346
49389
  recordQueryPath = {
49347
- node: ancestors[inlineFragmentLoc],
49348
- parentIndex: inlineFragmentLoc,
49390
+ node: ancestors[parentIndex],
49391
+ parentIndex,
49349
49392
  };
49393
+ break;
49350
49394
  }
49395
+ parentIndex++;
49351
49396
  }
49352
49397
  }
49353
49398
  return recordQueryPath;
@@ -49371,7 +49416,7 @@ function findAncesterPath(ancesters) {
49371
49416
  ? sectionPath
49372
49417
  : sectionPath === ''
49373
49418
  ? path
49374
- : `${sectionPath}_${path}`;
49419
+ : `${sectionPath}#${path}`;
49375
49420
  }
49376
49421
  }
49377
49422
  boundaryIndex = parentIndex;
@@ -49429,9 +49474,9 @@ function getRelation(node) {
49429
49474
  const relationships = args
49430
49475
  .map((arg) => arg.value)
49431
49476
  .filter(isStringValueNode)
49432
- .filter((valueNode) => valueNode.value === 'childRelationship' ||
49433
- valueNode.value === 'parentRelationship' ||
49434
- valueNode.value === 'polymorphicParentRelationship')
49477
+ .filter((valueNode) => valueNode.value === CHILD_RELATIONSHIP ||
49478
+ valueNode.value === PARENT_RELATIONSHIP ||
49479
+ valueNode.value === POLYMORPHIC_PARENT_RELATIONSHIP)
49435
49480
  .map((relationshipNode) => relationshipNode.value);
49436
49481
  if (relationships.length > 0) {
49437
49482
  return relationships[0];
@@ -49488,8 +49533,8 @@ function isFieldSpanning(node, parentNode) {
49488
49533
  */
49489
49534
  function isParentRelationship(node) {
49490
49535
  return (node &&
49491
- (isRelationship(node, 'parentRelationship') ||
49492
- isRelationship(node, 'polymorphicParentRelationship')));
49536
+ (isRelationship(node, PARENT_RELATIONSHIP) ||
49537
+ isRelationship(node, POLYMORPHIC_PARENT_RELATIONSHIP)));
49493
49538
  }
49494
49539
  /*
49495
49540
  checks if the InlineFragment spans
@@ -50322,8 +50367,8 @@ async function fetchIngestionTimeStampFromDatabase(apiName, info, args, query) {
50322
50367
  const results = await query(sql, [key]);
50323
50368
  const [timestamp] = results.rows.map((row) => row[0]);
50324
50369
  if (timestamp !== null && typeof timestamp === 'number') {
50325
- //go back 10 ms to adjust for margin of error when top level query is stored and when raml objects are stored
50326
- ingestionTimestamp = timestamp - 10;
50370
+ //go back 1000 ms to adjust for margin of error when top level query is stored and when raml objects are stored
50371
+ ingestionTimestamp = timestamp - 1000;
50327
50372
  }
50328
50373
  }
50329
50374
  return ingestionTimestamp;
@@ -50372,26 +50417,20 @@ function generateRecordQueries(objectInfos) {
50372
50417
  let recordConnections = ``;
50373
50418
  const polymorphicFieldTypeNames = new Set();
50374
50419
  let typedScalars = new Set();
50420
+ let parentRelationshipFields = new Set();
50375
50421
  for (const objectInfo of values$1(objectInfos)) {
50376
50422
  const { apiName, childRelationships } = objectInfo;
50377
50423
  let fields = ``;
50378
50424
  typedScalars.add(`${apiName}_Filter`);
50379
50425
  typedScalars.add(`${apiName}_OrderBy`);
50380
- for (const childRelationship of childRelationships) {
50381
- const { childObjectApiName } = childRelationship;
50382
- // Only add the relationship if there is relevant objectinfos for it,
50383
- // otherwise we'd be defining types we cannot satisfy and aren't referenced in
50384
- // the query.
50385
- if (objectInfos[childObjectApiName] !== undefined) {
50386
- fields += `${childRelationship.relationshipName}(first: Int, where: ${childObjectApiName}_Filter, orderBy: ${childObjectApiName}_OrderBy, scope: SupportedScopes): ${childObjectApiName}Connection \n`;
50387
- typedScalars.add(`${childObjectApiName}_Filter`);
50388
- typedScalars.add(`${childObjectApiName}_OrderBy`);
50389
- }
50390
- }
50391
50426
  for (const field of values$1(objectInfo.fields)) {
50392
50427
  if (!fieldsStaticallyAdded.includes(field.apiName)) {
50393
50428
  fields += `${field.apiName}: ${dataTypeToType(field.dataType, field.apiName)}\n`;
50394
50429
  }
50430
+ //handles parent relationship
50431
+ if (field.relationshipName === null) {
50432
+ continue;
50433
+ }
50395
50434
  // For spanning parent relationships with no union types
50396
50435
  if (field.referenceToInfos.length === 1) {
50397
50436
  const [relation] = field.referenceToInfos;
@@ -50399,11 +50438,13 @@ function generateRecordQueries(objectInfos) {
50399
50438
  // otherwise we'd be defining types we cannot satisfy and aren't referenced in
50400
50439
  // the query.
50401
50440
  if (objectInfos[relation.apiName] !== undefined) {
50441
+ parentRelationshipFields.add(field.relationshipName);
50402
50442
  fields += `${field.relationshipName}: ${relation.apiName}\n`;
50403
50443
  }
50404
50444
  // For polymorphic field, its type is 'Record' inteface. The concrete entity type name is saved for field resolving of next phase
50405
50445
  }
50406
50446
  else if (field.referenceToInfos.length > 1) {
50447
+ parentRelationshipFields.add(field.relationshipName);
50407
50448
  fields += `${field.relationshipName}: Record\n`;
50408
50449
  for (const relation of field.referenceToInfos) {
50409
50450
  if (objectInfos[relation.apiName] !== undefined) {
@@ -50412,6 +50453,20 @@ function generateRecordQueries(objectInfos) {
50412
50453
  }
50413
50454
  }
50414
50455
  }
50456
+ // handles child relationship
50457
+ for (const childRelationship of childRelationships) {
50458
+ const { childObjectApiName } = childRelationship;
50459
+ // Only add the relationship if there is relevant objectinfos for it,
50460
+ // otherwise we'd be defining types we cannot satisfy and aren't referenced in
50461
+ // the query.
50462
+ // If one field has both parent relationship and child relationship with the same name, the child relationship is ignored. This is how the server GQL has implemented as date of 08/07/2023
50463
+ if (objectInfos[childObjectApiName] !== undefined &&
50464
+ !parentRelationshipFields.has(childRelationship.relationshipName)) {
50465
+ fields += `${childRelationship.relationshipName}(first: Int, where: ${childObjectApiName}_Filter, orderBy: ${childObjectApiName}_OrderBy, scope: SupportedScopes): ${childObjectApiName}Connection \n`;
50466
+ typedScalars.add(`${childObjectApiName}_Filter`);
50467
+ typedScalars.add(`${childObjectApiName}_OrderBy`);
50468
+ }
50469
+ }
50415
50470
  recordQueries += `${apiName}(first: Int, where: ${apiName}_Filter, orderBy: ${apiName}_OrderBy, scope: SupportedScopes): ${apiName}Connection\n`;
50416
50471
  const isServiceAppointment = apiName === 'ServiceAppointment';
50417
50472
  recordConnections += /* GraphQL */ `
@@ -50571,7 +50626,7 @@ const parentRelationshipDirective = {
50571
50626
  },
50572
50627
  value: {
50573
50628
  kind: Kind.STRING,
50574
- value: 'parentRelationship',
50629
+ value: PARENT_RELATIONSHIP,
50575
50630
  block: false,
50576
50631
  },
50577
50632
  },
@@ -50585,8 +50640,8 @@ async function injectSyntheticFields(originalAST, objectInfoService, draftFuncti
50585
50640
  // example 2 'ServiceAppointment' -> ['Owner']; 'Owner' -> ['User', 'Group']
50586
50641
  const objectNodeInfoTree = {};
50587
50642
  // save the field path to apiName map
50588
- // example 1: 'ServiceAppointment' -> ['ServiceAppointment']; 'ServiceAppointment_Account' -> ['Account']; 'ServiceAppointment_Account_Owner' -> ['User']
50589
- const objectInfoApiMap = {};
50643
+ // example 1: 'ServiceAppointment' -> ['ServiceAppointment']; 'ServiceAppointment#ccount' -> ['Account']; 'ServiceAppointment#Account#Owner' -> ['User']
50644
+ const pathToObjectApiNamesMap = {};
50590
50645
  let startNodes = new Set();
50591
50646
  let totalNodes = new Set();
50592
50647
  let objectInfos = {};
@@ -50600,11 +50655,11 @@ async function injectSyntheticFields(originalAST, objectInfoService, draftFuncti
50600
50655
  visit(originalAST, {
50601
50656
  Argument: {
50602
50657
  enter(node, key, parent, path, ancestors) {
50603
- const recordQueryNode = findNearestRecordQuery(ancestors);
50604
- if (!recordQueryNode)
50658
+ const { connection: recordConnectionNode, path: ancesterPath } = findNearestConnectionWithPath(ancestors);
50659
+ if (!recordConnectionNode || !ancesterPath)
50605
50660
  return;
50606
- if (!objectNodeInfoTree[recordQueryNode.name.value]) {
50607
- objectNodeInfoTree[recordQueryNode.name.value] = [];
50661
+ if (!objectNodeInfoTree[ancesterPath]) {
50662
+ objectNodeInfoTree[ancesterPath] = [];
50608
50663
  }
50609
50664
  switch (node.name.value) {
50610
50665
  case 'orderBy':
@@ -50612,12 +50667,12 @@ async function injectSyntheticFields(originalAST, objectInfoService, draftFuncti
50612
50667
  if (node.value.kind !== 'ObjectValue') {
50613
50668
  return;
50614
50669
  }
50615
- totalNodes.add(recordQueryNode.name.value);
50670
+ totalNodes.add(ancesterPath);
50616
50671
  // 'childRelationship' node is not taken as the startNode of the 'NodeInfoTree' graph. The field scanning will construct the graph which lead here.
50617
- if (isRecordQuery(recordQueryNode)) {
50618
- startNodes.add(recordQueryNode.name.value);
50672
+ if (isRecordQuery(recordConnectionNode)) {
50673
+ startNodes.add(recordConnectionNode.name.value);
50619
50674
  }
50620
- growObjectFieldTree(objectNodeInfoTree, recordQueryNode.name.value, node.value, totalNodes, startNodes);
50675
+ growObjectFieldTree(objectNodeInfoTree, ancesterPath, node.value, totalNodes, startNodes);
50621
50676
  break;
50622
50677
  case 'scope':
50623
50678
  if (!isScopeArgumentNodeWithType(node, 'ASSIGNEDTOME', variables)) {
@@ -50632,17 +50687,16 @@ async function injectSyntheticFields(originalAST, objectInfoService, draftFuncti
50632
50687
  name: 'ServiceResources',
50633
50688
  });
50634
50689
  }
50635
- if (objectNodeInfoTree['ServiceResources'] === undefined) {
50636
- objectNodeInfoTree['ServiceResources'] = [];
50637
- }
50638
- if (!objectNodeInfoTree['ServiceResources'].some((child) => child.name === 'ServiceResource')) {
50639
- objectNodeInfoTree['ServiceResources'].push({
50640
- relation: 'parent',
50641
- name: 'ServiceResource',
50642
- });
50690
+ if (objectNodeInfoTree['ServiceAppointment#ServiceResources'] === undefined) {
50691
+ objectNodeInfoTree['ServiceAppointment#ServiceResources'] = [
50692
+ {
50693
+ relation: 'parent',
50694
+ name: 'ServiceResource',
50695
+ },
50696
+ ];
50643
50697
  }
50644
- if (objectNodeInfoTree['ServiceResource'] === undefined) {
50645
- objectNodeInfoTree['ServiceResource'] = [];
50698
+ if (objectNodeInfoTree['ServiceAppointment#ServiceResources#ServiceResource'] === undefined) {
50699
+ objectNodeInfoTree['ServiceAppointment#ServiceResources#ServiceResource'] = [];
50646
50700
  }
50647
50701
  break;
50648
50702
  default:
@@ -50656,7 +50710,7 @@ async function injectSyntheticFields(originalAST, objectInfoService, draftFuncti
50656
50710
  return;
50657
50711
  if (!node.selectionSet)
50658
50712
  return;
50659
- const recordQueryField = findNearestRecordQuery(ancestors);
50713
+ const recordQueryField = findNearestConnection(ancestors);
50660
50714
  //only injects fields for 'recordQuery' field. ignores the 'childRelationship' field since it will be traversed as the child of the 'recordQuery'
50661
50715
  if (isRecordQuery(recordQueryField) && recordQueryField) {
50662
50716
  totalNodes.add(recordQueryField.name.value);
@@ -50667,21 +50721,21 @@ async function injectSyntheticFields(originalAST, objectInfoService, draftFuncti
50667
50721
  },
50668
50722
  });
50669
50723
  if (objectInfoService && startNodes.size > 0) {
50670
- objectInfos = await resolveObjectInfos(objectNodeInfoTree, objectInfoApiMap, startNodes, objectInfoService);
50724
+ objectInfos = await resolveObjectInfos(objectNodeInfoTree, pathToObjectApiNamesMap, startNodes, objectInfoService);
50671
50725
  }
50672
50726
  // read pass; gather whats needed
50673
50727
  visit(originalAST, {
50674
50728
  Argument: {
50675
50729
  leave(node, key, parent, path, ancestors) {
50676
- const recordQueryField = findNearestRecordQuery(ancestors);
50730
+ const recordQueryField = findNearestConnection(ancestors);
50677
50731
  if (!recordQueryField)
50678
50732
  return;
50679
50733
  const ancestorPath = findAncesterPath(ancestors);
50680
50734
  if (!inlineFragmentSelections[ancestorPath]) {
50681
50735
  inlineFragmentSelections[ancestorPath] = [];
50682
50736
  }
50683
- const recordQueryApiName = objectInfoApiMap[ancestorPath]
50684
- ? objectInfoApiMap[ancestorPath][0]
50737
+ const recordQueryApiName = pathToObjectApiNamesMap[ancestorPath]
50738
+ ? pathToObjectApiNamesMap[ancestorPath][0]
50685
50739
  : recordQueryField.name.value;
50686
50740
  // The record node acts as the reference. The duplicated field in the record node is not injected
50687
50741
  const recordReferenceNode = [recordQueryField]
@@ -50695,7 +50749,7 @@ async function injectSyntheticFields(originalAST, objectInfoService, draftFuncti
50695
50749
  case 'scope':
50696
50750
  // Hanle 'MINE' field
50697
50751
  if (isScopeArgumentNodeWithType(node, 'MINE', variables)) {
50698
- if (isMineScopeAvailable(ancestorPath, objectInfoApiMap, objectInfos)) {
50752
+ if (isMineScopeAvailable(ancestorPath, pathToObjectApiNamesMap, objectInfos)) {
50699
50753
  // 'typeConditon' is added when the 'InlineFragmentNode' is appended at the write pass
50700
50754
  inlineFragmentSelections[ancestorPath].push(...mineFragmentSelections);
50701
50755
  }
@@ -50721,7 +50775,7 @@ async function injectSyntheticFields(originalAST, objectInfoService, draftFuncti
50721
50775
  case 'where': {
50722
50776
  inlineFragmentSelections[ancestorPath] = [
50723
50777
  ...inlineFragmentSelections[ancestorPath],
50724
- ...injectFilter(node, idState, ancestorPath, objectInfos, objectInfoApiMap, draftFunctions, recordReferenceNode),
50778
+ ...injectFilter(node, idState, ancestorPath, false, objectInfos, pathToObjectApiNamesMap, draftFunctions, recordReferenceNode),
50725
50779
  ];
50726
50780
  break;
50727
50781
  }
@@ -50737,7 +50791,7 @@ async function injectSyntheticFields(originalAST, objectInfoService, draftFuncti
50737
50791
  if (!node.selectionSet)
50738
50792
  return;
50739
50793
  // it could be 'recordQuery' or 'childRelationship'
50740
- const recordQueryField = findNearestRecordQuery(ancestors);
50794
+ const recordQueryField = findNearestConnection(ancestors);
50741
50795
  if (!recordQueryField)
50742
50796
  return;
50743
50797
  const ancestorPath = findAncesterPath(ancestors);
@@ -50749,7 +50803,7 @@ async function injectSyntheticFields(originalAST, objectInfoService, draftFuncti
50749
50803
  spanningSelections.push(selection);
50750
50804
  }
50751
50805
  }
50752
- const injectedFields = injectFields(spanningSelections, node, ancestors, objectInfos, objectInfoApiMap);
50806
+ const injectedFields = injectFields(spanningSelections, node, ancestorPath, ancestors, objectInfos, pathToObjectApiNamesMap);
50753
50807
  const mergedInjectedFields = mergeSelectionNodes$1(inlineFragmentSelections[ancestorPath], injectedFields);
50754
50808
  inlineFragmentSelections[ancestorPath] = mergedInjectedFields;
50755
50809
  },
@@ -50762,7 +50816,7 @@ async function injectSyntheticFields(originalAST, objectInfoService, draftFuncti
50762
50816
  // removes 'ServicesResources' query field node if 'assignedtome' scope shows up
50763
50817
  if (assignedtomeQueryFieldNode !== undefined &&
50764
50818
  node.name.value === 'ServiceResources') {
50765
- const serviceResourcesAncestor = findNearestRecordQuery(ancestors);
50819
+ const serviceResourcesAncestor = findNearestConnection(ancestors);
50766
50820
  if (serviceResourcesAncestor === assignedtomeQueryFieldNode) {
50767
50821
  return null;
50768
50822
  }
@@ -50771,7 +50825,7 @@ async function injectSyntheticFields(originalAST, objectInfoService, draftFuncti
50771
50825
  return;
50772
50826
  if (!node.selectionSet)
50773
50827
  return;
50774
- const recordQueryField = findNearestRecordQuery(ancestors);
50828
+ const recordQueryField = findNearestConnection(ancestors);
50775
50829
  if (!recordQueryField)
50776
50830
  return;
50777
50831
  const ancestorPath = findAncesterPath(ancestors);
@@ -50780,8 +50834,8 @@ async function injectSyntheticFields(originalAST, objectInfoService, draftFuncti
50780
50834
  return;
50781
50835
  //const recordQueryPath = findAncesterPath(ancestors);
50782
50836
  // 'apiName' has to be at index 0 since 'node' record type could only be of 'recordQuery' or 'childRelationship'. They can not have the 'InlineFragmentNode' as its children.
50783
- const recordQueryApiName = objectInfoApiMap[ancestorPath]
50784
- ? objectInfoApiMap[ancestorPath][0]
50837
+ const recordQueryApiName = pathToObjectApiNamesMap[ancestorPath]
50838
+ ? pathToObjectApiNamesMap[ancestorPath][0]
50785
50839
  : recordQueryField.name.value;
50786
50840
  const nodeWithFragments = {
50787
50841
  ...node,
@@ -50818,7 +50872,7 @@ async function injectSyntheticFields(originalAST, objectInfoService, draftFuncti
50818
50872
  if (node.name.value === 'where') {
50819
50873
  const ancestorPath = findAncesterPath(ancestors);
50820
50874
  if (idState.paths.includes(ancestorPath)) {
50821
- const apiName = objectInfoApiMap[ancestorPath][0];
50875
+ const apiName = pathToObjectApiNamesMap[ancestorPath][0];
50822
50876
  const objectInfo = objectInfos[apiName];
50823
50877
  const swappedIdFilter = swapIdField(node.value, objectInfo, false, idState, draftFunctions);
50824
50878
  return {
@@ -50884,8 +50938,8 @@ function swapIdField(filterFields, objectInfo, swapped, idState, draftFunctions)
50884
50938
  };
50885
50939
  }
50886
50940
  }
50887
- function isMineScopeAvailable(apiNamePath, objectInfoApiMap, objectInfos) {
50888
- const apiName = objectInfoApiMap[apiNamePath];
50941
+ function isMineScopeAvailable(apiNamePath, pathToObjectApiNamesMap, objectInfos) {
50942
+ const apiName = pathToObjectApiNamesMap[apiNamePath];
50889
50943
  if (!apiName)
50890
50944
  return false;
50891
50945
  const objectInfo = objectInfos[apiName[0]];
@@ -50974,15 +51028,16 @@ function growObjectFieldTree(tree, parentNode, entryNode, totalNodes, startNodes
50974
51028
  }
50975
51029
  // example: 'Account'
50976
51030
  const childNode = objectFieldNode.name.value;
51031
+ const childNodepath = `${parentNode}#${childNode}`;
50977
51032
  if (!tree[parentNode].some((child) => child.name === childNode)) {
50978
51033
  tree[parentNode].push({
50979
51034
  relation: 'parent',
50980
51035
  name: childNode,
50981
51036
  });
50982
- totalNodes.add(childNode);
51037
+ totalNodes.add(childNodepath);
50983
51038
  }
50984
51039
  // recursively go to deeper level of filter.
50985
- growObjectFieldTree(tree, childNode, objectFieldNode.value, totalNodes, startNodes);
51040
+ growObjectFieldTree(tree, childNodepath, objectFieldNode.value, totalNodes, startNodes);
50986
51041
  }
50987
51042
  }
50988
51043
  }
@@ -51017,19 +51072,20 @@ function growFieldTree(tree, parentSectionPath, entryNode, parentNode, totalNode
51017
51072
  }
51018
51073
  if (!tree[parentSectionPath].some((field) => field.name === fieldName)) {
51019
51074
  tree[parentSectionPath].push({
51020
- relation: relationType === 'parentRelationship' ||
51021
- relationType === 'polymorphicParentRelationship'
51075
+ relation: relationType === PARENT_RELATIONSHIP ||
51076
+ relationType === POLYMORPHIC_PARENT_RELATIONSHIP
51022
51077
  ? 'parent'
51023
51078
  : 'child',
51024
51079
  name: fieldName,
51025
51080
  });
51026
- totalNodes.add(fieldName);
51081
+ totalNodes.add(`${parentSectionPath}#${fieldName}`);
51027
51082
  }
51028
51083
  if (entryNode.selectionSet && entryNode.selectionSet.selections) {
51029
51084
  const childNodes = entryNode.selectionSet.selections.filter(isFieldOrInlineFragmentNode);
51030
51085
  // recursively build the traversal tree
51031
51086
  for (const child of childNodes) {
51032
- growFieldTree(tree, fieldName, child, entryNode, totalNodes, startNodes);
51087
+ const path = `${parentSectionPath}#${fieldName}`;
51088
+ growFieldTree(tree, path, child, entryNode, totalNodes, startNodes);
51033
51089
  }
51034
51090
  }
51035
51091
  }
@@ -51059,23 +51115,23 @@ function growFieldTree(tree, parentSectionPath, entryNode, parentNode, totalNode
51059
51115
  }
51060
51116
  if (!tree[parentSectionPath].some((field) => field.name === conditionName)) {
51061
51117
  tree[parentSectionPath].push({
51062
- relation: relationType === 'parentRelationship' ||
51063
- relationType === 'polymorphicParentRelationship'
51118
+ relation: relationType === PARENT_RELATIONSHIP ||
51119
+ relationType === POLYMORPHIC_PARENT_RELATIONSHIP
51064
51120
  ? 'parent'
51065
51121
  : 'child',
51066
51122
  name: conditionName,
51067
51123
  });
51068
- totalNodes.add(conditionName);
51124
+ const path = `${parentSectionPath}#${conditionName}`;
51125
+ totalNodes.add(path);
51069
51126
  }
51070
51127
  }
51071
51128
  }
51072
51129
  // dive deep immediately for 'InlineFragment'
51073
51130
  const childNodes = entryNode.selectionSet.selections.filter(isFieldOrInlineFragmentNode);
51131
+ const path = `${parentSectionPath}${entryNode.typeCondition ? '#' + entryNode.typeCondition.name.value : ''}`;
51074
51132
  // Navigates into InLineFragment
51075
51133
  for (const child of childNodes) {
51076
- growFieldTree(tree, entryNode.typeCondition
51077
- ? entryNode.typeCondition.name.value
51078
- : parentSectionPath, child, entryNode, totalNodes, startNodes);
51134
+ growFieldTree(tree, path, child, entryNode, totalNodes, startNodes);
51079
51135
  }
51080
51136
  }
51081
51137
  }
@@ -51087,7 +51143,7 @@ function growFieldTree(tree, parentSectionPath, entryNode, parentNode, totalNode
51087
51143
  * @param startNodes start nodes of the tree. It can be used to fetch ObjectInfo immediately
51088
51144
  * @param path
51089
51145
  */
51090
- async function resolveObjectInfos(objectInfotree, objectInfoApiMap, startNodes, objectInfoService) {
51146
+ async function resolveObjectInfos(objectInfotree, pathToObjectApiNamesMap, startNodes, objectInfoService) {
51091
51147
  let objectInfos;
51092
51148
  try {
51093
51149
  objectInfos = await objectInfoService.getObjectInfos(Array.from(startNodes));
@@ -51101,9 +51157,9 @@ async function resolveObjectInfos(objectInfotree, objectInfoApiMap, startNodes,
51101
51157
  throw new Error(`Unable to resolve ObjectInfo(s) for ${Array.from(startNodes)}`);
51102
51158
  }
51103
51159
  for (const startNode of startNodes) {
51104
- objectInfoApiMap[startNode] = [startNode];
51160
+ pathToObjectApiNamesMap[startNode] = [startNode];
51105
51161
  const children = objectInfotree[startNode];
51106
- const subObjectInfoMap = await fetchObjectInfos(objectInfotree, objectInfoApiMap, objectInfos, children, startNode, objectInfoService);
51162
+ const subObjectInfoMap = await fetchObjectInfos(objectInfotree, pathToObjectApiNamesMap, objectInfos, children, startNode, objectInfoService);
51107
51163
  objectInfos = { ...objectInfos, ...subObjectInfoMap };
51108
51164
  }
51109
51165
  return objectInfos;
@@ -51111,15 +51167,15 @@ async function resolveObjectInfos(objectInfotree, objectInfoApiMap, startNodes,
51111
51167
  // example 1: 'parentPath': 'ServiceAppointment', 'nodesAtSameLevel': ['Account']
51112
51168
  // example 2: 'parentPath': 'ServiceAppointment', 'nodesAtSameLevel': ['Owner'], this example has 2 apiName for the node 'Owner'
51113
51169
  // example 3: 'parentPath': 'ServiceAppointment_Owner', 'nodesAtSameLevel': ['User', 'Group']
51114
- async function fetchObjectInfos(objectInfotree, objectInfoApiMap, objectInfoMap, nodesAtSameLevel, parentPath, objectInfoService) {
51115
- const objectInfoApiNames = objectInfoApiMap[parentPath];
51170
+ async function fetchObjectInfos(objectInfotree, pathToObjectApiNamesMap, objectInfoMap, nodesAtSameLevel, parentPath, objectInfoService) {
51171
+ const objectInfoApiNames = pathToObjectApiNamesMap[parentPath];
51116
51172
  if (!objectInfoApiNames) {
51117
51173
  // eslint-disable-next-line
51118
51174
  throw new Error(`Object Info does not exist for ${parentPath}`);
51119
51175
  }
51120
51176
  const validObjectInfoNodes = [];
51121
51177
  let updatedObjectInfoMap = {};
51122
- // InlineFragment and polymorphic field support fits into this scenario ObjectInfoApiMap Entry: 'ServiceAppointment_Owner' -> ['User', 'Group']; ServiceAppointment_Owner_User' -> ['User']
51178
+ // InlineFragment and polymorphic field support fits into this scenario pathToObjectApiNamesMap Entry: 'ServiceAppointment#Owner' -> ['User', 'Group']; ServiceAppointment#Owner#User' -> ['User']
51123
51179
  if (objectInfoApiNames.length > 0 &&
51124
51180
  nodesAtSameLevel.length > 0 &&
51125
51181
  objectInfoApiNames.includes(nodesAtSameLevel[0].name)) {
@@ -51131,8 +51187,8 @@ async function fetchObjectInfos(objectInfotree, objectInfoApiMap, objectInfoMap,
51131
51187
  // eslint-disable-next-line
51132
51188
  throw new Error(`Condition ${field.name} does not exists for ${parentPath}`);
51133
51189
  }
51134
- const path = `${parentPath}_${field.name}`;
51135
- objectInfoApiMap[path] = [field.name];
51190
+ const path = `${parentPath}#${field.name}`;
51191
+ pathToObjectApiNamesMap[path] = [field.name];
51136
51192
  }
51137
51193
  validObjectInfoNodes.push(...nodesAtSameLevel);
51138
51194
  updatedObjectInfoMap = { ...objectInfoMap };
@@ -51147,7 +51203,7 @@ async function fetchObjectInfos(objectInfotree, objectInfoApiMap, objectInfoMap,
51147
51203
  let apiNames = [];
51148
51204
  for (const nodeInfo of nodesAtSameLevel) {
51149
51205
  const field = nodeInfo.name;
51150
- const path = `${parentPath}_${field}`;
51206
+ const path = `${parentPath}#${field}`;
51151
51207
  // Handle 'parentRelationship'
51152
51208
  if (nodeInfo.relation === 'parent') {
51153
51209
  const relationshipId = referenceIdFieldForRelationship(field);
@@ -51165,21 +51221,21 @@ async function fetchObjectInfos(objectInfotree, objectInfoApiMap, objectInfoMap,
51165
51221
  }
51166
51222
  }
51167
51223
  // This is a polymorphic field
51168
- if (fieldDefinition.referenceToInfos.length > 1 && objectInfotree[field]) {
51224
+ if (fieldDefinition.referenceToInfos.length > 1 && objectInfotree[path]) {
51169
51225
  // Fields needs to expand and heterogenous entity ObjectInfo needs to be fetched
51170
- const referencedNodeInfos = objectInfotree[field];
51226
+ const referencedNodeInfos = objectInfotree[path];
51171
51227
  const requestedApiNames = referencedNodeInfos.map((referenceNodeInfo) => referenceNodeInfo.name);
51172
51228
  // Fetches requested ObjectInfo only. Some entity's relation field could define more than 6 references. Only references show up in query need to be handled.
51173
- if (requestedApiNames.length > 0 && objectInfotree[field]) {
51229
+ if (requestedApiNames.length > 0 && objectInfotree[path]) {
51174
51230
  fieldDefinition.referenceToInfos
51175
51231
  .filter((referenceToInfo) => requestedApiNames.includes(referenceToInfo.apiName))
51176
51232
  .forEach((ref) => {
51177
- if (!objectInfoApiMap[path]) {
51178
- objectInfoApiMap[path] = [];
51233
+ if (!pathToObjectApiNamesMap[path]) {
51234
+ pathToObjectApiNamesMap[path] = [];
51179
51235
  }
51180
51236
  // 'ServiceAppointment_Owner' ->['User', 'Group']
51181
- if (!objectInfoApiMap[path].includes(ref.apiName)) {
51182
- objectInfoApiMap[path].push(ref.apiName);
51237
+ if (!pathToObjectApiNamesMap[path].includes(ref.apiName)) {
51238
+ pathToObjectApiNamesMap[path].push(ref.apiName);
51183
51239
  }
51184
51240
  if (!apiNames.includes(ref.apiName)) {
51185
51241
  apiNames.push(ref.apiName);
@@ -51189,11 +51245,11 @@ async function fetchObjectInfos(objectInfotree, objectInfoApiMap, objectInfoMap,
51189
51245
  }
51190
51246
  else if (fieldDefinition.referenceToInfos.length === 1) {
51191
51247
  const ref = fieldDefinition.referenceToInfos[0];
51192
- if (!objectInfoApiMap[path]) {
51193
- objectInfoApiMap[path] = [];
51248
+ if (!pathToObjectApiNamesMap[path]) {
51249
+ pathToObjectApiNamesMap[path] = [];
51194
51250
  }
51195
- if (!objectInfoApiMap[path].includes(ref.apiName)) {
51196
- objectInfoApiMap[path].push(ref.apiName);
51251
+ if (!pathToObjectApiNamesMap[path].includes(ref.apiName)) {
51252
+ pathToObjectApiNamesMap[path].push(ref.apiName);
51197
51253
  }
51198
51254
  if (!apiNames.includes(ref.apiName)) {
51199
51255
  apiNames.push(ref.apiName);
@@ -51204,11 +51260,11 @@ async function fetchObjectInfos(objectInfotree, objectInfoApiMap, objectInfoMap,
51204
51260
  // handles 'childRelationship'
51205
51261
  const childRelationship = parentObjectInfo.childRelationships.find((childRelationship) => childRelationship.relationshipName === field);
51206
51262
  if (childRelationship) {
51207
- if (!objectInfoApiMap[path]) {
51208
- objectInfoApiMap[path] = [];
51263
+ if (!pathToObjectApiNamesMap[path]) {
51264
+ pathToObjectApiNamesMap[path] = [];
51209
51265
  }
51210
- if (!objectInfoApiMap[path].includes(childRelationship.childObjectApiName)) {
51211
- objectInfoApiMap[path].push(childRelationship.childObjectApiName);
51266
+ if (!pathToObjectApiNamesMap[path].includes(childRelationship.childObjectApiName)) {
51267
+ pathToObjectApiNamesMap[path].push(childRelationship.childObjectApiName);
51212
51268
  }
51213
51269
  if (!apiNames.includes(childRelationship.childObjectApiName)) {
51214
51270
  apiNames.push(childRelationship.childObjectApiName);
@@ -51230,10 +51286,10 @@ async function fetchObjectInfos(objectInfotree, objectInfoApiMap, objectInfoMap,
51230
51286
  }
51231
51287
  for (const nodeInfo of validObjectInfoNodes) {
51232
51288
  const field = nodeInfo.name;
51233
- const subLevelFields = objectInfotree[field];
51234
- const path = `${parentPath}_${field}`;
51289
+ const path = `${parentPath}#${field}`;
51290
+ const subLevelFields = objectInfotree[path];
51235
51291
  if (subLevelFields && subLevelFields.length > 0) {
51236
- const subObjectInfos = await fetchObjectInfos(objectInfotree, objectInfoApiMap, updatedObjectInfoMap, subLevelFields, path, objectInfoService);
51292
+ const subObjectInfos = await fetchObjectInfos(objectInfotree, pathToObjectApiNamesMap, updatedObjectInfoMap, subLevelFields, path, objectInfoService);
51237
51293
  updatedObjectInfoMap = { ...updatedObjectInfoMap, ...subObjectInfos };
51238
51294
  }
51239
51295
  }
@@ -51248,27 +51304,29 @@ async function fetchObjectInfos(objectInfotree, objectInfoApiMap, objectInfoMap,
51248
51304
  * 'path' and 'queryNode' is 1 level above the 'filterNode'
51249
51305
  * @param filterNode filter node which needs to be injected. For example, 'State' ObjectFieldNode within filter 'where: { State: { eq: "Nova Scotia" }}'
51250
51306
  * @param idState ID state will be updated to determine if the ID fields in AST need to be swapped. The swapping happens later.
51251
- * @param path path to the current filterNode's parent. For example, path could be 'ServiceApointment' when filterNode is 'State'. If the path does not exist in 'objectInfoApiMap', parent node is not an field of relationship or recordQuery
51307
+ * @param parentPath path to the current filterNode's parent. For example, path could be 'ServiceApointment' when filterNode is 'State'. If the path does not exist in 'pathToObjectApiNamesMap', parent node is not an field of relationship or recordQuery
51308
+ * @param isParentPolymorphic true if parent points to a polymorphic field.
51252
51309
  * @param queryNode referece FieldNode which provides the information if 'filterNode' exist in it nor not.
51253
51310
  * @param objectInfos ObjectInfo map used in injection. If ObjectInfo misses or field does not exist in ObjectInfo, the error will be thrown
51254
- * @param objectInfoApiMap map used to locate the ObjectInfo. The key is path to a field, value is the ObjectInfo's apiName array. In the case of polymorphic fields, the apiName array have 2 or more elements. For example, 'ServiceAppointment' -> ['ServiceAppointment']; 'ServiceAppointment_Account' -> ['Account'], 'ServiceAppointment_Owner' -> ['User', 'Group'].
51311
+ * @param pathToObjectApiNamesMap map used to locate the ObjectInfo. The key is path to a field, value is the ObjectInfo's apiName array. In the case of polymorphic fields, the apiName array have 2 or more elements. For example, 'ServiceAppointment' -> ['ServiceAppointment']; 'ServiceAppointment_Account' -> ['Account'], 'ServiceAppointment_Owner' -> ['User', 'Group'].
51255
51312
  * @param draftFunctions functions for working with record ids that may be draft-created ids
51256
51313
  * @returns an array of nodes with injected fields
51257
51314
  */
51258
- function injectFilter(filterNode, idState, path, objectInfos, objectInfoApiMap, draftFunctions, queryNode) {
51315
+ function injectFilter(filterNode, idState, parentPath, isParentPolymorphic, objectInfos, pathToObjectApiNamesMap, draftFunctions, queryNode) {
51259
51316
  const injectedSelections = [];
51317
+ let isPolymorphicField = false;
51260
51318
  switch (filterNode.kind) {
51261
51319
  case Kind.ARGUMENT:
51262
51320
  if (filterNode.value.kind !== 'ObjectValue')
51263
51321
  return [];
51264
51322
  filterNode.value.fields.forEach((objectFieldNode) => {
51265
- let subResults = injectFilter(objectFieldNode, idState, path, objectInfos, objectInfoApiMap, draftFunctions, queryNode);
51323
+ let subResults = injectFilter(objectFieldNode, idState, parentPath, isParentPolymorphic, objectInfos, pathToObjectApiNamesMap, draftFunctions, queryNode);
51266
51324
  for (const subResult of subResults) {
51267
51325
  mergeOrAddToGroup(injectedSelections, subResult);
51268
51326
  }
51269
51327
  // multiple Ids might need to be swapped. remember their paths for faster write.
51270
51328
  if (idState.swapNeeded) {
51271
- idState.paths.push(path);
51329
+ idState.paths.push(parentPath);
51272
51330
  }
51273
51331
  });
51274
51332
  return injectedSelections;
@@ -51277,7 +51335,7 @@ function injectFilter(filterNode, idState, path, objectInfos, objectInfoApiMap,
51277
51335
  case Kind.LIST: {
51278
51336
  filterNode.value.values.filter(isObjectValueNode).forEach((objectValueNode) => {
51279
51337
  objectValueNode.fields.forEach((objectFieldNode) => {
51280
- const subResults = injectFilter(objectFieldNode, idState, path, objectInfos, objectInfoApiMap, draftFunctions, queryNode);
51338
+ const subResults = injectFilter(objectFieldNode, idState, parentPath, isParentPolymorphic, objectInfos, pathToObjectApiNamesMap, draftFunctions, queryNode);
51281
51339
  for (const subResult of subResults) {
51282
51340
  mergeOrAddToGroup(injectedSelections, subResult);
51283
51341
  }
@@ -51288,7 +51346,7 @@ function injectFilter(filterNode, idState, path, objectInfos, objectInfoApiMap,
51288
51346
  case Kind.OBJECT: {
51289
51347
  if (filterNode.name.value === 'not') {
51290
51348
  filterNode.value.fields.forEach((objectFieldNode) => {
51291
- const subResults = injectFilter(objectFieldNode, idState, path, objectInfos, objectInfoApiMap, draftFunctions, queryNode);
51349
+ const subResults = injectFilter(objectFieldNode, idState, parentPath, isParentPolymorphic, objectInfos, pathToObjectApiNamesMap, draftFunctions, queryNode);
51292
51350
  for (const subResult of subResults) {
51293
51351
  mergeOrAddToGroup(injectedSelections, subResult);
51294
51352
  }
@@ -51298,15 +51356,15 @@ function injectFilter(filterNode, idState, path, objectInfos, objectInfoApiMap,
51298
51356
  let apiNames = [];
51299
51357
  let isScalarField = false;
51300
51358
  //It is possible that this is a polymorphic field
51301
- apiNames = objectInfoApiMap[path];
51302
- // example: path: 'ServiceAppointment_LastModifiedDate'; filterNode: '{eq: {literal: LAST_WEEK}}'. queryNode: 'LastModifedDate { value}' FilterNode's parent has been verifed as a valid node
51359
+ apiNames = pathToObjectApiNamesMap[parentPath];
51360
+ // example: path: 'ServiceAppointment#LastModifiedDate'; filterNode: '{eq: {literal: LAST_WEEK}}'. queryNode: 'LastModifedDate { value}' FilterNode's parent has been verifed as a valid node
51303
51361
  if (apiNames === undefined) {
51304
51362
  isScalarField = true;
51305
51363
  }
51306
51364
  else {
51307
51365
  if (apiNames.some((apiName) => objectInfos[apiName] === undefined)) {
51308
51366
  // eslint-disable-next-line
51309
- throw new Error(`ObjectInfo is missing for ${path}`);
51367
+ throw new Error(`ObjectInfo is missing for ${parentPath}`);
51310
51368
  }
51311
51369
  }
51312
51370
  if (isScalarField) {
@@ -51328,29 +51386,19 @@ function injectFilter(filterNode, idState, path, objectInfos, objectInfoApiMap,
51328
51386
  }
51329
51387
  });
51330
51388
  let isSpanning = false;
51389
+ // if true, current node is a polymorphic concrete type node. For example, field node `User` under `Owner`
51331
51390
  let isInlineFragment = false;
51332
- let isPolymorphicField = false;
51333
51391
  let isTypeNameExisting = false;
51334
51392
  let curPath;
51335
51393
  let fieldName = filterNode.name.value;
51336
- curPath = `${path}_${fieldName}`;
51337
- if (objectInfoApiMap[curPath] && objectInfoApiMap[curPath].length > 0) {
51394
+ curPath = `${parentPath}#${fieldName}`;
51395
+ if (pathToObjectApiNamesMap[curPath] &&
51396
+ pathToObjectApiNamesMap[curPath].length > 0) {
51338
51397
  isSpanning = true;
51339
- if (objectInfoApiMap[curPath].length === 1) {
51340
- if (objectInfoApiMap[path] &&
51341
- objectInfoApiMap[path].length >= 1 &&
51342
- objectInfoApiMap[path].includes(objectInfoApiMap[curPath][0])) {
51343
- isInlineFragment = true;
51344
- }
51345
- }
51346
- // Checks if the current filter node is a polymorphic field. 'ServiceAppointment_Owner' --> ['User']; 'ServiceAppointment_Owner_User' --> ['User']
51347
- const childApiName = objectInfoApiMap[curPath][0];
51348
- const trialApiNames = objectInfoApiMap[`${curPath}_${childApiName}`];
51349
- if (trialApiNames !== undefined &&
51350
- trialApiNames.length === 1 &&
51351
- trialApiNames[0] === childApiName) {
51352
- isPolymorphicField = true;
51353
- }
51398
+ isInlineFragment =
51399
+ isParentPolymorphic &&
51400
+ pathToObjectApiNamesMap[curPath].length === 1;
51401
+ isPolymorphicField = isPolymorphicFieldPath(curPath, pathToObjectApiNamesMap, objectInfos);
51354
51402
  }
51355
51403
  // When filter node is at InLineFragment Level(a concrete entity of polymorphic field), query node is one level up. For example, ObjectFieldNode is ...{User:{...}}, queryNode is Owner:[User]
51356
51404
  if (isInlineFragment) {
@@ -51394,9 +51442,9 @@ function injectFilter(filterNode, idState, path, objectInfos, objectInfoApiMap,
51394
51442
  throw new Error(`Field ${fieldName} does not exist in ${apiNames[0]}`);
51395
51443
  }
51396
51444
  }
51397
- const objectInfoName = objectInfoApiMap[curPath] !== undefined
51398
- ? objectInfoApiMap[curPath][0]
51399
- : objectInfoApiMap[path][0];
51445
+ const objectInfoName = pathToObjectApiNamesMap[curPath] !== undefined
51446
+ ? pathToObjectApiNamesMap[curPath][0]
51447
+ : pathToObjectApiNamesMap[parentPath][0];
51400
51448
  const isIdField = isFieldAnIdField(filterNode.name.value, objectInfos[objectInfoName]);
51401
51449
  if (!isIdField) {
51402
51450
  let subSelectionNodes = [];
@@ -51408,7 +51456,7 @@ function injectFilter(filterNode, idState, path, objectInfos, objectInfoApiMap,
51408
51456
  updateIDInfo(subFieldNode, idState, draftFunctions);
51409
51457
  }
51410
51458
  // try injecting the fields within predicate no matter it has relation or not.
51411
- let subResults = injectFilter(subFieldNode, idState, curPath, objectInfos, objectInfoApiMap, draftFunctions, existingFields ? existingFields[0] : undefined);
51459
+ let subResults = injectFilter(subFieldNode, idState, curPath, isPolymorphicField, objectInfos, pathToObjectApiNamesMap, draftFunctions, existingFields ? existingFields[0] : undefined);
51412
51460
  subSelectionNodes = subSelectionNodes.concat(subResults);
51413
51461
  });
51414
51462
  if (!subFieldsHasId) {
@@ -51569,6 +51617,44 @@ function mergeOrAddToGroup(group, element) {
51569
51617
  }
51570
51618
  group.push(element);
51571
51619
  }
51620
+ // checks if the path points to a polymorphic field. For example, for the below `pathToObjectApiNamesMap`
51621
+ // {
51622
+ // 'ServiceAppointment' -> ['ServiceAppointment']
51623
+ // 'ServiceAppointment#Owner' --> ['User'],
51624
+ // 'ServiceAppointment#Owner#User' --> ['User']
51625
+ // }
51626
+ // path `ServiceAppointment#Owner` points to a polymorphic field, but path `ServiceAppointment#Owner#User` does not.
51627
+ function isPolymorphicFieldPath(path, pathToObjectApiNamesMap, objectInfos) {
51628
+ const lastSegmentIndex = path.lastIndexOf('#');
51629
+ if (lastSegmentIndex < 0) {
51630
+ return false;
51631
+ }
51632
+ const lastSegment = path.slice(lastSegmentIndex + 1);
51633
+ const parentApiPath = path.slice(0, lastSegmentIndex);
51634
+ if (pathToObjectApiNamesMap[parentApiPath] === undefined) {
51635
+ return false;
51636
+ }
51637
+ const parentObjectApiNames = pathToObjectApiNamesMap[parentApiPath];
51638
+ // If the last segment is a Polymorphic field, its immediate parent is a concrete object entity, which has 1 objectApiName mapped to the parent path in `pathToObjectApiNamesMap`.
51639
+ // For example, we like to check if `ServiceAppointment#Owner` path is polymorphic. The last segment is `Owner` and its parent `ServiceAppointment` has one element (which is also `ServiceAppointment`) array as its value.
51640
+ // Below are the entries in `pathToObjectApiNamesMap`
51641
+ // {
51642
+ // `ServiceAppointmen`t: [`ServiceAppointment`],
51643
+ // `ServiceAppointment#Owner`: [`User`, `Group`],
51644
+ // `ServiceAppointment#Owner#User`: [`User`],
51645
+ // `ServiceAppointment#Owner#Group`: [`Group`],
51646
+ // }
51647
+ if (parentObjectApiNames.length !== 1) {
51648
+ return false;
51649
+ }
51650
+ const parentObjectInfo = objectInfos[parentObjectApiNames[0]];
51651
+ const relationshipField = referenceIdFieldForRelationship(lastSegment);
51652
+ let fieldDefinition = parentObjectInfo.fields[relationshipField];
51653
+ if (fieldDefinition === undefined) {
51654
+ return false;
51655
+ }
51656
+ return fieldDefinition.polymorphicForeignKey;
51657
+ }
51572
51658
  function isFieldAnIdField(fieldName, objectInfo) {
51573
51659
  if (fieldName === 'Id')
51574
51660
  return true;
@@ -51621,10 +51707,10 @@ function updateIDInfo(fieldNode, idState, draftFunctions) {
51621
51707
  * @param parentNode parent node of param 1
51622
51708
  * @param ancestors ancester of param 1
51623
51709
  * @param objectInfos ObjectInfo map used in injection. If ObjectInfo misses or field does not exist in ObjectInfo, the error will be thrown
51624
- * @param objectInfoApiMap map used to locate the ObjectInfo. The key is path to a field, value is the ObjectInfo's apiName array. In the case of polymorphic fields, the apiName array have 2 or more elements. For example, 'ServiceAppointment' -> ['ServiceAppointment']; 'ServiceAppointment_Account' -> ['Account'], 'ServiceAppointment_Owner' -> ['User', 'Group'].
51710
+ * @param pathToObjectApiNamesMap map used to locate the ObjectInfo. The key is path to a field, value is the ObjectInfo's apiName array. In the case of polymorphic fields, the apiName array have 2 or more elements. For example, 'ServiceAppointment' -> ['ServiceAppointment']; 'ServiceAppointment#Account' -> ['Account'], 'ServiceAppointment#Owner' -> ['User', 'Group'].
51625
51711
  * @return injected SelectionNodes used to construct the InlineFragment.
51626
51712
  */
51627
- function injectFields(selections, parentNode, ancestors, objectInfos, objectInfoApiMap) {
51713
+ function injectFields(selections, parentNode, parentPath, ancestors, objectInfos, pathToObjectApiNamesMap) {
51628
51714
  /**
51629
51715
  * 1 parentship can return 2 FieldNode which need to be flattened
51630
51716
  * Concact: { ** Contact { ** ContactId {
@@ -51642,6 +51728,10 @@ function injectFields(selections, parentNode, ancestors, objectInfos, objectInfo
51642
51728
  if (!selection.selectionSet) {
51643
51729
  return selection;
51644
51730
  }
51731
+ const segment = isFieldNode(selection)
51732
+ ? selection.name.value
51733
+ : selection.typeCondition.name.value;
51734
+ const curPath = `${parentPath}#${segment}`;
51645
51735
  const spanningSubSelections = [];
51646
51736
  for (const subSelection of selection.selectionSet.selections) {
51647
51737
  if (isFieldSpanning(subSelection, selection)) {
@@ -51649,7 +51739,7 @@ function injectFields(selections, parentNode, ancestors, objectInfos, objectInfo
51649
51739
  }
51650
51740
  }
51651
51741
  // Handles multiple level field injection like 'ServiceAppointment' --> 'Account' --> 'Owner'
51652
- const subInjectedSelections = injectFields(spanningSubSelections, selection, ancestors, objectInfos, objectInfoApiMap);
51742
+ const subInjectedSelections = injectFields(spanningSubSelections, selection, curPath, ancestors, objectInfos, pathToObjectApiNamesMap);
51653
51743
  if (!selection.selectionSet) {
51654
51744
  return selection;
51655
51745
  }
@@ -51692,7 +51782,7 @@ function injectFields(selections, parentNode, ancestors, objectInfos, objectInfo
51692
51782
  }
51693
51783
  }
51694
51784
  // For polymorphic fields, the Id field is excluded.
51695
- const excludeId = selection.selectionSet.selections.every(isInlineFragmentNode);
51785
+ const excludeId = isPolymorphicFieldPath(curPath, pathToObjectApiNamesMap, objectInfos);
51696
51786
  const idSelection = [];
51697
51787
  if (!excludeId && !hasIdAlready) {
51698
51788
  idSelection.push({
@@ -51703,8 +51793,8 @@ function injectFields(selections, parentNode, ancestors, objectInfos, objectInfo
51703
51793
  },
51704
51794
  });
51705
51795
  }
51706
- // Inject '__typename' for polymorphic fields. '__typename' field acts as a reference to concrete type of a polymorphic field and is used to match JSON response with AST node. For more detail,
51707
- // please reference 'removeSyntheticFields'.
51796
+ // Inject '__typename' for InlineFragment. '__typename' field acts as a reference to concrete type of a polymorphic field or a standard field in the returned GQL response, which equals to
51797
+ // `typedCondition` of the InlineFragment in the query AST. It is used to match JSON response with AST node. For more detail, please reference 'removeSyntheticFields'.
51708
51798
  if (isInlineFragmentNode(selection) &&
51709
51799
  !selection.selectionSet.selections.find((selection) => isFieldNode(selection) && selection.name.value === '__typename')) {
51710
51800
  idSelection.push({
@@ -51738,7 +51828,7 @@ function injectFields(selections, parentNode, ancestors, objectInfos, objectInfo
51738
51828
  if (isFieldNode(parentNode) && parentNode.selectionSet && parentNode.name.value === 'node') {
51739
51829
  if (parentNode.selectionSet.selections
51740
51830
  .filter(isFieldOrInlineFragmentNode)
51741
- .some((selectionNode) => isRelationship(selectionNode, 'childRelationship'))) {
51831
+ .some((selectionNode) => isRelationship(selectionNode, CHILD_RELATIONSHIP))) {
51742
51832
  if (!parentNode.selectionSet.selections
51743
51833
  .filter(isFieldNode)
51744
51834
  .some((sibling) => sibling.name.value === 'Id')) {
@@ -51757,15 +51847,15 @@ function injectFields(selections, parentNode, ancestors, objectInfos, objectInfo
51757
51847
  if (parentInfo.parentIndex >= 0) {
51758
51848
  // example node { TimeSheetEntries { edges { node { Id }}}}
51759
51849
  const parent = parentInfo.node;
51760
- if (isRelationship(parent, 'childRelationship')) {
51850
+ if (isRelationship(parent, CHILD_RELATIONSHIP)) {
51761
51851
  const unVisitedAncestors = ancestors.slice(0, parentInfo.parentIndex);
51762
51852
  // path : "TimeSheet"
51763
51853
  const grandParentPath = findAncesterPath(unVisitedAncestors);
51764
- if (objectInfoApiMap &&
51765
- objectInfoApiMap[grandParentPath] &&
51854
+ if (pathToObjectApiNamesMap &&
51855
+ pathToObjectApiNamesMap[grandParentPath] &&
51766
51856
  objectInfos &&
51767
- objectInfos[objectInfoApiMap[grandParentPath][0]]) {
51768
- const grandParentObjectInfo = objectInfos[objectInfoApiMap[grandParentPath][0]];
51857
+ objectInfos[pathToObjectApiNamesMap[grandParentPath][0]]) {
51858
+ const grandParentObjectInfo = objectInfos[pathToObjectApiNamesMap[grandParentPath][0]];
51769
51859
  // exmaple "TimeSheetEntries"
51770
51860
  const parentFieldName = parent.name.value;
51771
51861
  const targetRelationship = grandParentObjectInfo.childRelationships.find((childRelationship) => {
@@ -51886,7 +51976,7 @@ const assignedToMeFragmentSelections = [
51886
51976
  },
51887
51977
  value: {
51888
51978
  kind: 'StringValue',
51889
- value: 'childRelationship',
51979
+ value: CHILD_RELATIONSHIP,
51890
51980
  block: false,
51891
51981
  },
51892
51982
  },
@@ -51978,7 +52068,7 @@ const assignedToMeFragmentSelections = [
51978
52068
  },
51979
52069
  value: {
51980
52070
  kind: 'StringValue',
51981
- value: 'parentRelationship',
52071
+ value: PARENT_RELATIONSHIP,
51982
52072
  block: false,
51983
52073
  },
51984
52074
  },
@@ -52115,7 +52205,9 @@ function handleNonArrayJsonProperty(selection, fieldName, jsonInput, jsonOutput)
52115
52205
  jsonOutput[fieldName] = null;
52116
52206
  return;
52117
52207
  }
52118
- jsonOutput[fieldName] = {};
52208
+ if (jsonOutput[fieldName] === undefined) {
52209
+ jsonOutput[fieldName] = {};
52210
+ }
52119
52211
  createUserJsonOutput(selection, jsonInput[fieldName], jsonOutput[fieldName]);
52120
52212
  }
52121
52213
  else {
@@ -56990,6 +57082,9 @@ class PrimingSession extends EventEmitter {
56990
57082
  this.ldsRecordRefresher = config.ldsRecordRefresher;
56991
57083
  this.networkWorkerPool = new AsyncWorkerPool(this.concurrency);
56992
57084
  this.useBatchGQL = ldsPrimingGraphqlBatch.isOpen({ fallback: false });
57085
+ if (this.useBatchGQL) {
57086
+ this.batchSize = this.batchSize / DEFAULT_GQL_QUERY_BATCH_SIZE;
57087
+ }
56993
57088
  this.conflictPool = new ConflictPool(config.store, this.objectInfoLoader);
56994
57089
  }
56995
57090
  // function that enqueues priming work
@@ -57846,7 +57941,7 @@ register({
57846
57941
  id: '@salesforce/lds-network-adapter',
57847
57942
  instrument: instrument$1,
57848
57943
  });
57849
- // version: 1.229.0-dev1-f69d054a9
57944
+ // version: 1.229.0-dev3-175ac936b
57850
57945
 
57851
57946
  const { create: create$2, keys: keys$2 } = Object;
57852
57947
  const { stringify: stringify$1, parse: parse$1 } = JSON;
@@ -72609,6 +72704,7 @@ function buildSelectionForField$7(source, reader, sel, variables, fragments, isC
72609
72704
  }
72610
72705
  if (fieldData === null) {
72611
72706
  reader.assignScalar(requestedFieldName, sink, fieldData);
72707
+ reader.exitPath();
72612
72708
  return sink;
72613
72709
  }
72614
72710
  const fieldType = getFieldType(sel);
@@ -76292,7 +76388,7 @@ register({
76292
76388
  configuration: { ...configurationForGraphQLAdapters },
76293
76389
  instrument,
76294
76390
  });
76295
- // version: 1.229.0-dev1-5b6d3db67
76391
+ // version: 1.229.0-dev3-71194d134
76296
76392
 
76297
76393
  // On core the unstable adapters are re-exported with different names,
76298
76394
 
@@ -78539,7 +78635,7 @@ withDefaultLuvio((luvio) => {
78539
78635
  unstable_graphQL_imperative = createImperativeAdapter(luvio, createInstrumentedAdapter(ldsAdapter, adapterMetadata), adapterMetadata);
78540
78636
  graphQLImperative = ldsAdapter;
78541
78637
  });
78542
- // version: 1.229.0-dev1-5b6d3db67
78638
+ // version: 1.229.0-dev3-71194d134
78543
78639
 
78544
78640
  var gqlApi = /*#__PURE__*/Object.freeze({
78545
78641
  __proto__: null,
@@ -79253,4 +79349,4 @@ const { luvio } = getRuntime();
79253
79349
  setDefaultLuvio({ luvio });
79254
79350
 
79255
79351
  export { createPrimingSession, draftManager, draftQueue, executeAdapter, executeMutatingAdapter, getImperativeAdapterNames, invokeAdapter, invokeAdapterWithDraftToReplace, invokeAdapterWithMetadata, nimbusDraftQueue, registerReportObserver, setMetadataTTL, setUiApiRecordTTL, subscribeToAdapter };
79256
- // version: 1.229.0-dev1-f69d054a9
79352
+ // version: 1.229.0-dev3-175ac936b