diff --git a/src/store/__tests__/RelayStoreData_cacheManager-test.js b/src/store/__tests__/RelayStoreData_cacheManager-test.js index 50d4241308e24..475fad3d7de3d 100644 --- a/src/store/__tests__/RelayStoreData_cacheManager-test.js +++ b/src/store/__tests__/RelayStoreData_cacheManager-test.js @@ -25,7 +25,8 @@ var RelayConnectionInterface = require('RelayConnectionInterface'); var RelayMockCacheManager = require('RelayMockCacheManager'); var RelayMutationType = require('RelayMutationType'); var RelayStoreData = require('RelayStoreData'); -var generateRQLFieldAlias = require('generateRQLFieldAlias'); + +var transformRelayQueryPayload = require('transformRelayQueryPayload'); describe('RelayStoreData', function() { var cacheManager; @@ -274,10 +275,10 @@ describe('RelayStoreData', function() { } } `); - var response = { + var response = transformRelayQueryPayload(query, { node: { id: '123', - [generateRQLFieldAlias('friends.first(2)')]: { + friends: { edges: [ { node: { @@ -298,7 +299,7 @@ describe('RelayStoreData', function() { }, }, }, - }; + }); storeData.handleQueryPayload(query, response); expect(cacheManager).toContainCalledMethods({ @@ -362,10 +363,10 @@ describe('RelayStoreData', function() { } } `); - var response = { + var response = transformRelayQueryPayload(query, { node: { id: '123', - [generateRQLFieldAlias('friends.first(2)')]: { + friends: { edges: [], [PAGE_INFO]: { [HAS_PREV_PAGE]: false, @@ -373,7 +374,7 @@ describe('RelayStoreData', function() { }, }, }, - }; + }); storeData.handleQueryPayload(query, response); expect(cacheManager).toContainCalledMethods({ @@ -460,10 +461,10 @@ describe('RelayStoreData', function() { } } `); - var response = { + var response = transformRelayQueryPayload(query, { node: { id: '123', - [generateRQLFieldAlias('comments.first(1)')]: { + comments: { count: 2, edges: [ { @@ -479,7 +480,7 @@ describe('RelayStoreData', function() { }, }, } - }; + }); storeData.handleQueryPayload(query, response); var configs = [{ @@ -581,10 +582,10 @@ describe('RelayStoreData', function() { } } `); - var response = { + var response = transformRelayQueryPayload(query, { node: { id: '123', - [generateRQLFieldAlias('comments.first(1)')]: { + comments: { count: 2, edges: [ { @@ -600,7 +601,7 @@ describe('RelayStoreData', function() { }, }, } - }; + }); storeData.handleQueryPayload(query, response); var configs = [{ diff --git a/src/tools/__mocks__/RelayTestUtils.js b/src/tools/__mocks__/RelayTestUtils.js index 2f1d2951a77db..c5421d954ed2e 100644 --- a/src/tools/__mocks__/RelayTestUtils.js +++ b/src/tools/__mocks__/RelayTestUtils.js @@ -480,8 +480,12 @@ var RelayTestUtils = { var RelayChangeTracker = require('RelayChangeTracker'); var RelayQueryTracker = require('RelayQueryTracker'); var RelayQueryWriter = require('RelayQueryWriter'); + var transformRelayQueryPayload = require('transformRelayQueryPayload'); var writeRelayQueryPayload = require('writeRelayQueryPayload'); + // rewrite any plain name/alias property names into storage keys + payload = transformRelayQueryPayload(query, payload); + tracker = tracker || new RelayQueryTracker(); options = options || {}; var changeTracker = new RelayChangeTracker(); diff --git a/src/tools/__mocks__/transformRelayQueryPayload.js b/src/tools/__mocks__/transformRelayQueryPayload.js new file mode 100644 index 0000000000000..4903a27e62a2d --- /dev/null +++ b/src/tools/__mocks__/transformRelayQueryPayload.js @@ -0,0 +1,149 @@ +/** + * Copyright 2013-2015, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + * + * @providesModule transformRelayQueryPayload + * @flow + * @typechecks + */ + +'use strict'; + +var RelayQuery = require('RelayQuery'); +var RelayQueryVisitor = require('RelayQueryVisitor'); + +var invariant = require('invariant'); +var mapObject = require('mapObject'); + +type Payload = mixed; +type PayloadState = { + client: Payload, + server: Payload, +}; + +/** + * Transforms "client" payloads with property keys that match the "application" + * names (i.e. property names are schema names or aliases) into "server" + * payloads that match what the server would return for the given query (i.e. + * property names are serialization keys instead). + */ +function transformRelayQueryPayload( + root: RelayQuery.Root, + clientData: Payload +): Payload { + // Handle both FB & OSS formats for root payloads on plural calls: FB + // returns objects with array values, OSS returns arrays. + if (clientData == null) { + return clientData; + } else if (Array.isArray(clientData)) { + return clientData.map(item => transform(root, item)); + } else { + invariant( + typeof clientData === 'object', + 'transformClientPayload(): Expected the root payload for query `%s` ' + + 'to be an array or object, got `%s`.', + root.getName(), + clientData + ); + return mapObject(clientData, item => { + if (Array.isArray(item)) { + return item.map(innerItem => transform(root, innerItem)); + } + return transform(root, item); + }); + } +} + +function transform( + root: RelayQuery.Root, + clientData: Payload +): Payload { + if (clientData == null) { + return clientData; + } + var transform = new RelayPayloadTransformer(); + var serverData = {}; + transform.visit(root, { + client: clientData, + server: serverData, + }); + return serverData; +} + +class RelayPayloadTransformer extends RelayQueryVisitor { + visitField( + node: RelayQuery.Field, + state: PayloadState + ): ?RelayQuery.Node { + var {client, server} = state; + // `client` represents the *parent* node value and should not be null + // due to checks before traversing child values. + invariant( + typeof client === 'object' && client !== null, + 'RelayPayloadTransformer: Expected a client value for field `%s`.', + node.getApplicationName() + ); + invariant( + typeof server === 'object' && server !== null, + 'RelayPayloadTransformer: Expected a server value for field `%s`.', + node.getApplicationName() + ); + var applicationName = node.getApplicationName(); + var serializationKey = node.getSerializationKey(); + var clientData = client[applicationName]; + var serverData = server[serializationKey]; + + if (node.isScalar() || clientData == null) { + server[serializationKey] = clientData; + } else if (Array.isArray(clientData)) { + invariant( + serverData == null || Array.isArray(serverData), + 'RelayPayloadTransformer: Got conflicting values for field `%s`: ' + + 'expected values to be arrays.', + applicationName + ); + if (serverData == null) { + server[serializationKey] = serverData = []; + } + clientData.forEach((clientItem, index) => { + if (clientItem == null) { + serverData[index] = clientItem; + return; + } + var serverItem = serverData && serverData[index]; + if (serverItem == null) { + serverData[index] = serverItem = {}; + } + this.traverse(node, { + client: clientItem, + server: serverItem, + }); + }); + } else { + invariant( + typeof clientData === 'object' && clientData !== null, + 'RelayPayloadTransformer: Expected an object value for field `%s`.', + applicationName + ); + invariant( + serverData == null || typeof serverData === 'object', + 'RelayPayloadTransformer: Got conflicting values for field `%s`: ' + + 'expected values to be objects.', + applicationName + ); + if (serverData == null) { + server[serializationKey] = serverData = {}; + } + this.traverse(node, { + client: clientData, + server: serverData, + }); + } + } +} + +module.exports = transformRelayQueryPayload; diff --git a/src/tools/__tests__/transformRelayQueryPayload-test.js b/src/tools/__tests__/transformRelayQueryPayload-test.js new file mode 100644 index 0000000000000..ab5333c2ff8f3 --- /dev/null +++ b/src/tools/__tests__/transformRelayQueryPayload-test.js @@ -0,0 +1,213 @@ +/** + * Copyright 2013-2015, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + * + * @emails oncall+relay + */ + +'use strict'; + +var RelayTestUtils = require('RelayTestUtils'); +RelayTestUtils.unmockRelay(); + +var Relay = require('Relay'); +var generateRQLFieldAlias = require('generateRQLFieldAlias'); +var transformRelayQueryPayload = require('transformRelayQueryPayload'); + +describe('transformClientPayload()', () => { + var {getNode} = RelayTestUtils; + + it('transforms singular root payloads', () => { + var query = getNode(Relay.QL` + query { + node(id: "123") { + friends(first:"1") { + count, + edges { + node { + id, + ... on User { + profilePicture(size: "32") { + uri, + }, + }, + }, + }, + }, + } + } + `); + var payload = { + node: { + id: '123', + friends: { + count: 1, + edges: [ + { + cursor: 'friend:cursor', + node: { + id: 'client:friend', + profilePicture: { + uri: 'friend.jpg', + }, + }, + }, + ], + }, + }, + }; + expect(transformRelayQueryPayload(query, payload)).toEqual({ + node: { + id: '123', + [generateRQLFieldAlias('friends.first(1)')]: { + count: 1, + edges: [ + { + cursor: 'friend:cursor', + node: { + id: 'client:friend', + [generateRQLFieldAlias('profilePicture.size(32)')]: { + uri: 'friend.jpg', + }, + }, + }, + ], + }, + }, + }); + }); + + it('transforms plural root payloads of arrays', () => { + var query = getNode(Relay.QL` + query { + nodes(ids: ["123", "456"]) { + ... on User { + profilePicture(size: "32") { + uri, + }, + }, + }, + } + `); + var payload = { + 123: { + id: '123', + profilePicture: { + uri: '123.jpg', + }, + }, + 456: { + id: '456', + profilePicture: { + uri: '456.jpg', + }, + }, + }; + expect(transformRelayQueryPayload(query, payload)).toEqual({ + 123: { + id: '123', + [generateRQLFieldAlias('profilePicture.size(32)')]: { + uri: '123.jpg', + }, + }, + 456: { + id: '456', + [generateRQLFieldAlias('profilePicture.size(32)')]: { + uri: '456.jpg', + }, + }, + }); + }); + + it('transforms plural root payloads of objects (OSS)', () => { + var query = getNode(Relay.QL` + query { + nodes(ids: ["123", "456"]) { + ... on User { + profilePicture(size: "32") { + uri, + }, + }, + }, + } + `); + var payload = [ + { + id: '123', + profilePicture: { + uri: '123.jpg', + }, + }, + { + id: '456', + profilePicture: { + uri: '456.jpg', + }, + }, + ]; + expect(transformRelayQueryPayload(query, payload)).toEqual([ + { + id: '123', + [generateRQLFieldAlias('profilePicture.size(32)')]: { + uri: '123.jpg', + }, + }, + { + id: '456', + [generateRQLFieldAlias('profilePicture.size(32)')]: { + uri: '456.jpg', + }, + }, + ]); + }); + + it('transforms plural root payloads of objects (FB)', () => { + var query = getNode(Relay.QL` + query { + nodes(ids: ["123", "456"]) { + ... on User { + profilePicture(size: "32") { + uri, + }, + }, + }, + } + `); + var payload = { + nodes: [ + { + id: '123', + profilePicture: { + uri: '123.jpg', + }, + }, + { + id: '456', + profilePicture: { + uri: '456.jpg', + }, + }, + ], + }; + expect(transformRelayQueryPayload(query, payload)).toEqual({ + nodes: [ + { + id: '123', + [generateRQLFieldAlias('profilePicture.size(32)')]: { + uri: '123.jpg', + }, + }, + { + id: '456', + [generateRQLFieldAlias('profilePicture.size(32)')]: { + uri: '456.jpg', + }, + }, + ], + }); + }); +}); diff --git a/src/traversal/__tests__/diffRelayQuery_connection-test.js b/src/traversal/__tests__/diffRelayQuery_connection-test.js index b3328a6770992..328fb80c8243e 100644 --- a/src/traversal/__tests__/diffRelayQuery_connection-test.js +++ b/src/traversal/__tests__/diffRelayQuery_connection-test.js @@ -24,7 +24,6 @@ var RelayConnectionInterface = require('RelayConnectionInterface'); var RelayNodeInterface = require('RelayNodeInterface'); var RelayQueryTracker = require('RelayQueryTracker'); var diffRelayQuery = require('diffRelayQuery'); -var generateRQLFieldAlias = require('generateRQLFieldAlias'); describe('diffRelayQuery', () => { var RelayRecordStore; @@ -76,10 +75,9 @@ describe('diffRelayQuery', () => { var store = new RelayRecordStore({records}, {map: rootCallMap}); var tracker = new RelayQueryTracker(); - var alias = generateRQLFieldAlias('newsFeed.first(3)'); var payload = { viewer: { - [alias]: { + newsFeed: { edges: [ {cursor: 'c1', node: {id: 's1'}}, {cursor: 'c2', node: {id: 's2'}}, @@ -119,10 +117,9 @@ describe('diffRelayQuery', () => { var tracker = new RelayQueryTracker(); // Write full data for 3 of 5 records, nothing for edges 4-5 - var alias = generateRQLFieldAlias('newsFeed.first(5)'); var payload = { viewer: { - [alias]: { + newsFeed: { edges: [ {cursor: 'c1', node: {id: 's1'}}, {cursor: 'c2', node: {id: 's2'}}, @@ -176,22 +173,6 @@ describe('diffRelayQuery', () => { var tracker = new RelayQueryTracker(); // Provide empty IDs to simulate non-refetchable nodes - var alias = generateRQLFieldAlias('newsFeed.first(3)'); - var payload = { - viewer: { - [alias]: { - edges: [ - {cursor: 'c1', node: {id:'', message:{text:'s1'}}}, - {cursor: 'c2', node: {id:'', message:{text:'s1'}}}, - {cursor: 'c3', node: {id:'', message:{text:'s1'}}}, - ], - [PAGE_INFO]: { - [HAS_NEXT_PAGE]: true, - [HAS_PREV_PAGE]: false, - }, - }, - }, - }; var writeQuery = getNode(Relay.QL` query { viewer { @@ -207,6 +188,21 @@ describe('diffRelayQuery', () => { } } `); + var payload = { + viewer: { + newsFeed: { + edges: [ + {cursor: 'c1', node: {id:'', message:{text:'s1'}}}, + {cursor: 'c2', node: {id:'', message:{text:'s1'}}}, + {cursor: 'c3', node: {id:'', message:{text:'s1'}}}, + ], + [PAGE_INFO]: { + [HAS_NEXT_PAGE]: true, + [HAS_PREV_PAGE]: false, + }, + }, + }, + }; writePayload(store, writeQuery, payload, tracker); // `feedback{id}` is missing but there is no way to refetch it @@ -241,10 +237,9 @@ describe('diffRelayQuery', () => { var store = new RelayRecordStore({records}, {map: rootCallMap}); var tracker = new RelayQueryTracker(); - var alias = generateRQLFieldAlias('newsFeed.first(3)'); var payload = { viewer: { - [alias]: { + newsFeed: { edges: [ {cursor: 'c1', node: {id:'s1', message:{text:'s1'}}}, {cursor: 'c2', node: {id:'s2', message:{text:'s1'}}}, @@ -339,10 +334,9 @@ describe('diffRelayQuery', () => { var store = new RelayRecordStore({records}, {map: rootCallMap}); var tracker = new RelayQueryTracker(); - var alias = generateRQLFieldAlias('newsFeed.first(3)'); var payload = { viewer: { - [alias]: { + newsFeed: { edges: [ {cursor: 'c1', node: {id:'s1', message:{text:'s1'}}}, {cursor: 'c2', node: {id:'s2', message:{text:'s1'}}}, @@ -492,10 +486,9 @@ describe('diffRelayQuery', () => { var store = new RelayRecordStore({records}, {map: rootCallMap}); var tracker = new RelayQueryTracker(); - var alias = generateRQLFieldAlias('notificationStories.first(3)'); var payload = { viewer: { - [alias]: { + notificationStories: { edges: [ {cursor: 'c1', node: {id:'s1', message:{text:'s1'}}}, {cursor: 'c2', node: {id:'s2', message:{text:'s1'}}}, @@ -598,10 +591,9 @@ describe('diffRelayQuery', () => { var store = new RelayRecordStore({records}, {map: rootCallMap}); var tracker = new RelayQueryTracker(); - var alias = generateRQLFieldAlias('newsFeed.first(1)'); var payload = { viewer: { - [alias]: { + newsFeed: { edges: [ {cursor: 'c1', node: {id:'s1', message:{text:'s1'}}}, ], diff --git a/src/traversal/__tests__/writeRelayQueryPayload_connectionField-test.js b/src/traversal/__tests__/writeRelayQueryPayload_connectionField-test.js index 6bc7d69b25613..34ac4619676d1 100644 --- a/src/traversal/__tests__/writeRelayQueryPayload_connectionField-test.js +++ b/src/traversal/__tests__/writeRelayQueryPayload_connectionField-test.js @@ -20,7 +20,6 @@ jest var Relay = require('Relay'); var RelayConnectionInterface = require('RelayConnectionInterface'); -var generateRQLFieldAlias = require('generateRQLFieldAlias'); var RelayMetaRoute = require('RelayMetaRoute'); var RelayQuery = require('RelayQuery'); @@ -71,11 +70,10 @@ describe('writeRelayQueryPayload()', () => { } `); - var alias = generateRQLFieldAlias('friends.first(3)'); var payload = { node: { id: '123', - [alias]: { + friends: { edges: [], [PAGE_INFO]: { [HAS_NEXT_PAGE]: false, @@ -134,43 +132,42 @@ describe('writeRelayQueryPayload()', () => { `); var payload = { node: { - id: '123' - } - }; - var alias = generateRQLFieldAlias('friends.first(3)'); - payload.node[alias] = { - edges: [ - { - cursor: 'friend1', - node: { - id: 'friend1ID' - }, - source: { - id: '123' - } - }, - { - cursor: 'friend2', - node: { - id: 'friend2ID' + id: '123', + friends: { + edges: [ + { + cursor: 'friend1', + node: { + id: 'friend1ID' + }, + source: { + id: '123' + } + }, + { + cursor: 'friend2', + node: { + id: 'friend2ID' + }, + source: { + id: '123' + } + }, + { + cursor: 'friend3', + node: { + id: 'friend3ID' + }, + source: { + id: '123' + } + } + ], + [PAGE_INFO]: { + [HAS_NEXT_PAGE]: true, + [HAS_PREV_PAGE]: false, }, - source: { - id: '123' - } }, - { - cursor: 'friend3', - node: { - id: 'friend3ID' - }, - source: { - id: '123' - } - } - ], - [PAGE_INFO]: { - [HAS_NEXT_PAGE]: true, - [HAS_PREV_PAGE]: false, }, }; var results = writePayload(store, query, payload); @@ -232,27 +229,26 @@ describe('writeRelayQueryPayload()', () => { `); var payload = { node: { - id: '123' - } - }; - var alias = generateRQLFieldAlias('friends.first(3)'); - payload.node[alias] = { - edges: [ - null, - { - cursor: 'friend2', - node: null, - }, - { - cursor: 'friend3', - node: { - id: 'friend3ID' + id: '123', + friends: { + edges: [ + null, + { + cursor: 'friend2', + node: null, + }, + { + cursor: 'friend3', + node: { + id: 'friend3ID' + }, + } + ], + [PAGE_INFO]: { + [HAS_NEXT_PAGE]: true, + [HAS_PREV_PAGE]: false, }, - } - ], - [PAGE_INFO]: { - [HAS_NEXT_PAGE]: true, - [HAS_PREV_PAGE]: false, + }, }, }; var results = writePayload(store, query, payload); @@ -324,25 +320,24 @@ describe('writeRelayQueryPayload()', () => { `); payload = { node: { - id: '123' - } - }; - var alias = generateRQLFieldAlias('friends.first(1)'); - payload.node[alias] = { - edges: [ - { - cursor: 'friend1', - node: { - id: 'friend1ID' + id: '123', + friends: { + edges: [ + { + cursor: 'friend1', + node: { + id: 'friend1ID' + }, + source: { + id: '123' + } + }, + ], + [PAGE_INFO]: { + [HAS_NEXT_PAGE]: true, + [HAS_PREV_PAGE]: false, }, - source: { - id: '123' - } }, - ], - [PAGE_INFO]: { - [HAS_NEXT_PAGE]: true, - [HAS_PREV_PAGE]: false, }, }; var results = writePayload(store, query, payload); @@ -397,11 +392,10 @@ describe('writeRelayQueryPayload()', () => { } } `); - var alias = generateRQLFieldAlias('friends.isViewerFriend(true)'); var payload = { node: { id: '123', - [alias]: { + friends: { edges: [ { cursor: 'friend1', @@ -446,20 +440,19 @@ describe('writeRelayQueryPayload()', () => { `); var payload = { node: { - id: '123' - } - }; - var alias = generateRQLFieldAlias('friends.first(1)'); - payload.node[alias] = { - edges: [{ - node: { - id: 'node1' + id: '123', + friends: { + edges: [{ + node: { + id: 'node1' + }, + cursor: 'cursor1' + }], + [PAGE_INFO]: { + [HAS_NEXT_PAGE]: true, + [HAS_PREV_PAGE]: false, + }, }, - cursor: 'cursor1' - }], - [PAGE_INFO]: { - [HAS_NEXT_PAGE]: true, - [HAS_PREV_PAGE]: false, }, }; var records = {}; @@ -483,20 +476,19 @@ describe('writeRelayQueryPayload()', () => { `); var payload = { node: { - id: '123' - } - }; - var alias = generateRQLFieldAlias('friends.first(1).after(cursor1)'); - payload.node[alias] = { - edges: [{ - node: { - id: 'node2' + id: '123', + friends: { + edges: [{ + node: { + id: 'node2' + }, + cursor: 'cursor2' + }], + [PAGE_INFO]: { + [HAS_NEXT_PAGE]: true, + [HAS_PREV_PAGE]: true, + }, }, - cursor: 'cursor2' - }], - [PAGE_INFO]: { - [HAS_NEXT_PAGE]: true, - [HAS_PREV_PAGE]: true, }, }; var results = writePayload(store, query, payload); @@ -544,21 +536,20 @@ describe('writeRelayQueryPayload()', () => { `); var payload = { node: { - id: '123' - } - }; - var alias = generateRQLFieldAlias('friends.find(node1)'); - payload.node[alias] = { - edges: [{ - node: { - id: 'node1', - name: 'Tim' // added field + id: '123', + friends: { + edges: [{ + node: { + id: 'node1', + name: 'Tim' // added field + }, + cursor: 'cursor1' + }], + [PAGE_INFO]: { + [HAS_NEXT_PAGE]: true, + [HAS_PREV_PAGE]: true, + }, }, - cursor: 'cursor1' - }], - [PAGE_INFO]: { - [HAS_NEXT_PAGE]: true, - [HAS_PREV_PAGE]: true, }, }; var results = writePayload(store, query, payload); @@ -607,23 +598,22 @@ describe('writeRelayQueryPayload()', () => { `, RelayMetaRoute.get('$RelayTest'), {}); var payload = { node: { - id: '123' - } - }; - var alias = generateRQLFieldAlias('friends.find(node1)'); - payload.node[alias] = { - edges: [{ - node: { - id: 'node1', - }, - source: { // new edge field - id: '456' + 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, + }, }, - cursor: 'cursor1' - }], - [PAGE_INFO]: { - [HAS_NEXT_PAGE]: true, - [HAS_PREV_PAGE]: true, }, }; var results = writePayload(store, query, payload); @@ -672,20 +662,19 @@ describe('writeRelayQueryPayload()', () => { `); var payload = { node: { - id: '123' - } - }; - var alias = generateRQLFieldAlias('friends.first(1)'); - payload.node[alias] = { - edges: [{ - node: { - id: 'node1b' + id: '123', + friends: { + edges: [{ + node: { + id: 'node1b' + }, + cursor: 'cursor1b' + }], + [PAGE_INFO]: { + [HAS_NEXT_PAGE]: true, + [HAS_PREV_PAGE]: false, + }, }, - cursor: 'cursor1b' - }], - [PAGE_INFO]: { - [HAS_NEXT_PAGE]: true, - [HAS_PREV_PAGE]: false, }, }; var results = writePayload(store, query, payload); @@ -732,20 +721,19 @@ describe('writeRelayQueryPayload()', () => { `); var payload = { node: { - id: '123' - } - }; - var alias = generateRQLFieldAlias('friends.first(1)'); - payload.node[alias] = { - edges: [{ - node: { - id: 'node1b' + id: '123', + friends: { + edges: [{ + node: { + id: 'node1b' + }, + cursor: 'cursor1b' + }], + [PAGE_INFO]: { + [HAS_NEXT_PAGE]: true, + [HAS_PREV_PAGE]: false, + }, }, - cursor: 'cursor1b' - }], - [PAGE_INFO]: { - [HAS_NEXT_PAGE]: true, - [HAS_PREV_PAGE]: false, }, }; var results = writePayload(store, query, payload, null, {forceIndex: 1}); diff --git a/src/traversal/__tests__/writeRelayQueryPayload_paths-test.js b/src/traversal/__tests__/writeRelayQueryPayload_paths-test.js index 231212262a230..0a703342a42fd 100644 --- a/src/traversal/__tests__/writeRelayQueryPayload_paths-test.js +++ b/src/traversal/__tests__/writeRelayQueryPayload_paths-test.js @@ -22,7 +22,6 @@ var Relay = require('Relay'); var RelayQueryPath = require('RelayQueryPath'); var RelayQueryTracker = require('RelayQueryTracker'); var invariant = require('invariant'); -var generateRQLFieldAlias = require('generateRQLFieldAlias'); describe('writePayload()', () => { var RelayRecordStore; @@ -223,11 +222,10 @@ describe('writePayload()', () => { } } `); - var alias = generateRQLFieldAlias('friends.first(1)'); var payload = { node: { id: '123', - [alias]: { + friends: { edges: [ { cursor: 'cursor1', @@ -427,11 +425,10 @@ describe('writePayload()', () => { } } `); - var alias = generateRQLFieldAlias('friends.first(1)'); var payload = { node: { id: '123', - [alias]: { + friends: { edges: [ { cursor: 'c1', @@ -487,11 +484,10 @@ describe('writePayload()', () => { } } `); - var alias = generateRQLFieldAlias('friends.first(1)'); var payload = { node: { id: '123', - [alias]: { + friends: { edges: [ { cursor: 'c1', @@ -523,11 +519,10 @@ describe('writePayload()', () => { } } `); - alias = generateRQLFieldAlias('friends.after(c1).first(1)'); payload = { node: { id: '123', - [alias]: { + friends: { edges: [ { cursor: 'c2', @@ -579,7 +574,6 @@ describe('writePayload()', () => { } } `); - var alias = generateRQLFieldAlias('friends.first(1)'); var payload = { node: { id: '123', @@ -591,7 +585,7 @@ describe('writePayload()', () => { }, }, ], - [alias]: { + friends: { edges: [ { cursor: 'c1', diff --git a/src/traversal/__tests__/writeRelayUpdatePayload-test.js b/src/traversal/__tests__/writeRelayUpdatePayload-test.js index 3b86627478add..8efd7052eba4d 100644 --- a/src/traversal/__tests__/writeRelayUpdatePayload-test.js +++ b/src/traversal/__tests__/writeRelayUpdatePayload-test.js @@ -28,7 +28,6 @@ var RelayMutationType = require('RelayMutationType'); var RelayQueryWriter = require('RelayQueryWriter'); var GraphQLMutatorConstants = require('GraphQLMutatorConstants'); var generateClientEdgeID = require('generateClientEdgeID'); -var generateRQLFieldAlias = require('generateRQLFieldAlias'); var writeRelayUpdatePayload = require('writeRelayUpdatePayload'); describe('writePayload()', () => { @@ -85,7 +84,7 @@ describe('writePayload()', () => { var payload = { node: { id: 'feedback_id', - [generateRQLFieldAlias('topLevelComments.first(1)')]: { + topLevelComments: { count: 1, edges: [ { @@ -303,11 +302,10 @@ describe('writePayload()', () => { } } `); - var alias = generateRQLFieldAlias('topLevelComments.first(1)'); var payload = { node: { id: feedbackID, - [alias]: { + topLevelComments: { count: 1, edges: [ { @@ -715,11 +713,10 @@ describe('writePayload()', () => { } } `); - var alias = generateRQLFieldAlias('topLevelComments.first(1)'); var payload = { node: { id: feedbackID, - [alias]: { + topLevelComments: { count: 1, edges: [ {