コード例 #1
0
ファイル: RelayModernEnvironment.js プロジェクト: nodkz/relay
 isSelectorLoading(selector: Selector): boolean {
   const key = deferrableFragmentKey(
     selector.dataID,
     selector.node.name,
     selector.variables,
   );
   return this._deferrableSelections.has(key);
 }
コード例 #2
0
 node.selections.forEach(selection => {
   if (selection.kind === SCALAR_FIELD || selection.kind === LINKED_FIELD) {
     this._normalizeField(node, selection, record, data);
   } else if (selection.kind === CONDITION) {
     const conditionValue = this._getVariableValue(selection.condition);
     if (conditionValue === selection.passingValue) {
       this._traverseSelections(selection, record, data);
     }
   } else if (selection.kind === INLINE_FRAGMENT) {
     const typeName = RelayModernRecord.getType(record);
     if (typeName === selection.type) {
       this._traverseSelections(selection, record, data);
     }
   } else if (
     selection.kind === LINKED_HANDLE ||
     selection.kind === SCALAR_HANDLE
   ) {
     const args = selection.args
       ? getArgumentValues(selection.args, this._variables)
       : {};
     const fieldKey = getStorageKey(selection, this._variables);
     const handleKey = getHandleStorageKey(selection, this._variables);
     this._handleFieldPayloads.push({
       args,
       dataID: RelayModernRecord.getDataID(record),
       fieldKey,
       handle: selection.handle,
       handleKey,
     });
   } else if (selection.kind === DEFERRABLE_FRAGMENT_SPREAD) {
     const dataID = RelayModernRecord.getDataID(record);
     const value = RelayModernRecord.getValue(record, selection.storageKey);
     invariant(
       typeof value === 'string',
       'expected ID at %s',
       selection.storageKey,
     );
     const variables = selection.args
       ? getArgumentValues(selection.args, {
           ...this._variables,
           [selection.rootFieldVariable]: value,
         })
       : {};
     const key = deferrableFragmentKey(dataID, selection.name, variables);
     this._deferrableSelections.add(key);
   } else {
     invariant(
       false,
       'RelayResponseNormalizer(): Unexpected ast kind `%s`.',
       selection.kind,
     );
   }
 });
コード例 #3
0
ファイル: RelayModernEnvironment.js プロジェクト: nodkz/relay
 next: executePayload => {
   const responsePayload = normalizePayload(executePayload);
   const {source, fieldPayloads, deferrableSelections} = responsePayload;
   for (const selectionKey of deferrableSelections || new Set()) {
     this._deferrableSelections.add(selectionKey);
   }
   if (executePayload.isOptimistic) {
     invariant(
       optimisticResponse == null,
       'environment.execute: only support one optimistic respnose per ' +
         'execute.',
     );
     optimisticResponse = {
       source: source,
       fieldPayloads: fieldPayloads,
     };
     this._publishQueue.applyUpdate(optimisticResponse);
     this._publishQueue.run();
   } else {
     if (optimisticResponse) {
       this._publishQueue.revertUpdate(optimisticResponse);
       optimisticResponse = undefined;
     }
     const writeSelector = createOperationSelector(
       operation.node,
       executePayload.variables,
       executePayload.operation,
     );
     if (executePayload.operation.kind === 'DeferrableOperation') {
       const fragmentKey = deferrableFragmentKey(
         executePayload.variables[
           executePayload.operation.rootFieldVariable
         ],
         executePayload.operation.fragmentName,
         getOperationVariables(
           executePayload.operation,
           executePayload.variables,
         ),
       );
       this._deferrableSelections.delete(fragmentKey);
     }
     this._publishQueue.commitPayload(
       writeSelector,
       responsePayload,
       updater,
     );
     this._publishQueue.run();
   }
 },