it('converts singular calls with null values', () => { const relayCalls = [{ name: 'size', value: 32, }]; const graphqlCalls = [RelayTestUtils.createCall('size', 32)]; expect(callsFromGraphQL(graphqlCalls)).toEqual(relayCalls); expect(callsToGraphQL(relayCalls)).toEqual(graphqlCalls); });
it('converts calls with array values', () => { const relayCalls = [{ name: 'size', value: [32, 64], }]; const graphqlCalls = [RelayTestUtils.createCall('size', [32, 64])]; expect(callsFromGraphQL(graphqlCalls)).toEqual(relayCalls); expect(callsToGraphQL(relayCalls)).toEqual(graphqlCalls); });
it('converts array calls without values', () => { const relayCalls = [ { name: 'size', type: '[Int]', value: [], }, ]; const graphqlCalls = [RelayTestUtils.createCall('size', [], '[Int]')]; expect(callsFromGraphQL(graphqlCalls)).toEqual(relayCalls); expect(callsToGraphQL(relayCalls)).toEqual(graphqlCalls); });
/** * Checks to see if we have a range client ID (eg. `someID_first(25)`), and if * so, unpacks the range metadata, stashing it into (and overriding) `state`. */ _handleRangeInfo(node: RelayQuery.Field, state: State): void { var rangeData = this._rangeData.parseRangeClientID( state.storeDataID ); if (rangeData != null) { state.componentDataID = state.storeDataID; state.storeDataID = rangeData.dataID; state.rangeInfo = this._recordStore.getRangeMetadata( state.storeDataID, callsFromGraphQL(rangeData.calls, rangeData.callValues) ); } }
getCall(): Call { let calls = this.__calls__; if (!calls) { const concreteCalls = (this.__concreteNode__: ConcreteMutation).calls; if (concreteCalls) { calls = callsFromGraphQL(concreteCalls, this.__variables__); } else { calls = EMPTY_CALLS; } this.__calls__ = calls; } return calls[0]; }
getCallsWithValues(): Array<Call> { let calls = this.__calls__; if (!calls) { const concreteCalls = (this.__concreteNode__: ConcreteQuery).calls; if (concreteCalls) { calls = callsFromGraphQL(concreteCalls, this.__variables__); } else { calls = EMPTY_CALLS; } this.__calls__ = calls; } return calls; }
/** * Returns a token that can be parsed using parseRangeClientID to recover * the attributes needed to retrieve the corresponding items from a * GraphQLRange. * * @param {array<*>} calls * @param {object} callValues * @param {string} dataID * @return {string} */ getClientIDForRangeWithID(calls, callValues, dataID) { var callsAsString = callsFromGraphQL(calls, callValues) .map(call => serializeRelayQueryCall(call).substring(1)) .join(','); var key = dataID + '_' + callsAsString; var edge = this._rangeData[key]; if (!edge) { this._rangeData[key] = { dataID: dataID, calls: calls, callValues: callValues, }; let rangeDataKeys = this._rangeDataKeyMap[dataID]; if (!rangeDataKeys) { this._rangeDataKeyMap[dataID] = rangeDataKeys = []; } rangeDataKeys.push(key); } return key; }
return this.__concreteNode__.directives.map(directive => { return { args: callsFromGraphQL(directive.args, this.__variables__), name: directive.name, }; });