beforeEach(() => {
   const route = RelayMetaRoute.get('$fetchRelayQuery');
   const queryA = RelayQuery.Root.create(
     Relay.QL`query{node(id:"123"){id}}`, route, {}
   );
   const queryB = RelayQuery.Root.create(
     Relay.QL`query{node(id:"456"){id}}`, route, {}
   );
   requestA = new RelayQueryRequest(queryA);
   requestB = new RelayQueryRequest(queryB);
 });
Example #2
0
function createRelayQuery(
  node: Object,
  variables: {[key: string]: mixed}
): RelayQuery.Root {
  invariant(
    typeof variables === 'object' &&
    variables != null &&
    !Array.isArray(variables),
    'Relay.Query: Expected `variables` to be an object.'
  );
  return RelayQuery.Root.create(
    node,
    RelayMetaRoute.get('$createRelayQuery'),
    variables
  );
}
Example #3
0
 Object.keys(route.queries).forEach(queryName => {
   if (!Component.hasFragment(queryName)) {
     warning(
       false,
       'Relay.QL: query `%s.queries.%s` is invalid, expected fragment ' +
       '`%s.fragments.%s` to be defined.',
       route.name,
       queryName,
       Component.displayName,
       queryName
     );
     return;
   }
   var queryBuilder = route.queries[queryName];
   if (queryBuilder) {
     var concreteQuery = buildRQL.Query(
       queryBuilder,
       Component,
       queryName,
       route.params
     );
     invariant(
       concreteQuery !== undefined,
       'Relay.QL: query `%s.queries.%s` is invalid, a typical query is ' +
       'defined using: () => Relay.QL`query { ... }`.',
       route.name,
       queryName
     );
     if (concreteQuery) {
       var rootQuery = RelayQuery.Root.create(
         concreteQuery,
         RelayMetaRoute.get(route.name),
         route.params
       );
       const identifyingArg = rootQuery.getIdentifyingArg();
       if (!identifyingArg || identifyingArg.value !== undefined) {
         querySet[queryName] = rootQuery;
         return;
       }
     }
   }
   querySet[queryName] = null;
 });
 it('updates the range when edge data changes', () => {
   // NOTE: Hack to preserve `source{id}` in all environments for now.
   const query = RelayQuery.Root.create(Relay.QL`
     query {
       node(id:"123") {
         friends(find:"node1") {
           edges {
             node {
               id
             }
             source {
               id
             }
           }
         }
       }
     }
   `, RelayMetaRoute.get('$RelayTest'), {});
   const payload = {
     node: {
       id: '123',
       friends: {
         edges: [{
           node: {
             id: 'node1',
           },
           source: { // new edge field
             id: '456',
           },
           cursor: 'cursor1',
         }],
         [PAGE_INFO]: {
           [HAS_NEXT_PAGE]: true,
           [HAS_PREV_PAGE]: true,
         },
       },
       __typename: 'User',
     },
   };
   const results = writePayload(store, writer, query, payload);
   expect(results).toEqual({
     created: {
       '456': true, // `source` added
     },
     updated: {
       'client:1': true, // range updated because an edge had a change
       'client:client:1:node1': true, // `source` added to edge
     },
   });
   expect(store.getRangeMetadata('client:1', [
     {name: 'first', value: 1},
   ])).toEqual({
     diffCalls: [],
     filterCalls: [],
     pageInfo: {
       [END_CURSOR]: 'cursor1',
       [HAS_NEXT_PAGE]: true,
       [HAS_PREV_PAGE]: false,
       [START_CURSOR]: 'cursor1',
     },
     requestedEdgeIDs: ['client:client:1:node1'],
     filteredEdges: [
       {edgeID: 'client:client:1:node1', nodeID: 'node1'},
     ],
   });
   const sourceID = store.getLinkedRecordID('client:client:1:node1', 'source');
   expect(sourceID).toBe('456');
   expect(store.getField(sourceID, 'id')).toBe('456');
 });
Example #5
0
    invariant(
      match,
      'getRefNode(): Expected call variable of the form `<ref_q\\d+>`.',
    );
    // e.g. `q0`
    const id = match[1];
    // e.g. `{ref_q0: '<ref_q0>'}`
    const variables = {[name]: '<' + callValue.callVariableName + '>'};

    return RelayQuery.Root.create(
      {
        ...node,
        calls: [
          QueryBuilder.createCall(
            'id',
            QueryBuilder.createBatchCallVariable(id, refParam.path),
          ),
        ],
        isDeferred: true,
      },
      RelayMetaRoute.get('$RelayTestUtils'),
      variables,
    );
  },

  getVerbatimNode(node, variables) {
    return RelayTestUtils.filterGeneratedFields(
      RelayTestUtils.getNode(node, variables),
    );
  },

  filterGeneratedFields(query) {