Пример #1
0
 it('returns the path for non-refetchable records', () => {
   const records = {};
   const store = new RelayRecordStore({records});
   const writer = new RelayRecordWriter(records, {}, false);
   const query = getNode(Relay.QL`
     query {
       viewer {
         actor {
           address {
             city
           }
         }
       }
     }
   `);
   const actorID = '123';
   const addressID = 'client:1';
   const path = RelayQueryPath.getPath(
     RelayQueryPath.getPath(
       RelayQueryPath.create(query),
       query.getFieldByStorageKey('actor'),
       actorID
     ),
     query.getFieldByStorageKey('actor').getFieldByStorageKey('address'),
     addressID
   );
   writer.putRecord(addressID, 'Type', path);
   expect(store.getPathToRecord(addressID)).toMatchPath(path);
 });
Пример #2
0
 /**
  * Given a query fragment and a data ID, returns a root query that applies
  * the fragment to the object specified by the data ID.
  */
 buildFragmentQueryForDataID(
   fragment: RelayQuery.Fragment,
   dataID: DataID
 ): RelayQuery.Root {
   if (RelayRecord.isClientID(dataID)) {
     const path = this._queuedStore.getPathToRecord(
       this._rangeData.getCanonicalClientID(dataID),
     );
     invariant(
       path,
       'RelayStoreData.buildFragmentQueryForDataID(): Cannot refetch ' +
       'record `%s` without a path.',
       dataID
     );
     return path.getQuery(fragment);
   }
   // Fragment fields cannot be spread directly into the root because they
   // may not exist on the `Node` type.
   return RelayQuery.Root.build(
     fragment.getDebugName() || 'UnknownQuery',
     RelayNodeInterface.NODE,
     dataID,
     [fragment],
     {identifyingArgName: RelayNodeInterface.ID},
     NODE_TYPE
   );
 }
Пример #3
0
 it('returns undefined for refetchable records', () => {
   const records = {};
   const store = new RelayRecordStore({records});
   const writer = new RelayRecordWriter(records, {}, false);
   const query = getNode(Relay.QL`
     query {
       viewer {
         actor {
           id
         }
       }
     }
   `);
   const actorID = '123';
   const path = RelayQueryPath.getPath(
     RelayQueryPath.create(query),
     query.getFieldByStorageKey('actor'),
     actorID
   );
   writer.putRecord(actorID, 'Type', path);
   expect(store.getPathToRecord(actorID)).toBe(undefined);
 });
Пример #4
0
 /**
  * Given a query fragment and a data ID, returns a root query that applies
  * the fragment to the object specified by the data ID.
  */
 buildFragmentQueryForDataID(
   fragment: RelayQuery.Fragment,
   dataID: DataID
 ): RelayQuery.Root {
   if (RelayRecord.isClientID(dataID)) {
     const path = this._queuedStore.getPathToRecord(
       this._rangeData.getCanonicalClientID(dataID),
     );
     invariant(
       path,
       'RelayStoreData.buildFragmentQueryForDataID(): Cannot refetch ' +
       'record `%s` without a path.',
       dataID
     );
     return RelayQueryPath.getQuery(
       this._cachedStore,
       path,
       fragment
     );
   }
   // Fragment fields cannot be spread directly into the root because they
   // may not exist on the `Node` type.
   return RelayQuery.Root.build(
     fragment.getDebugName() || 'UnknownQuery',
     NODE,
     dataID,
     [idField, typeField, fragment],
     {
       identifyingArgName: ID,
       identifyingArgType: ID_TYPE,
       isAbstract: true,
       isDeferred: false,
       isPlural: false,
     },
     NODE_TYPE
   );
 }