Skip to content

Commit

Permalink
Fix getRangeBehavior to allow non-string calls
Browse files Browse the repository at this point in the history
Summary:
Fixes #1208

That `invariant` doesn't seem to make sense in that function, removing it will allow us to use `rangeBehavior` functions with other types than string.

josephsavona
Closes #1216

Reviewed By: wincent

Differential Revision: D3440535

Pulled By: kassens

fbshipit-source-id: 35038900382425843075de2c592cee0da2c566f1
  • Loading branch information
xuorig authored and Facebook Github Bot 3 committed Jun 16, 2016
1 parent 42530dc commit c9fb0e8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
6 changes: 6 additions & 0 deletions src/mutation/__tests__/getRangeBehavior-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ describe('getRangeBehavior()', () => {
const rangeBehavior = getRangeBehavior(rangeBehaviors, calls);
expect(rangeBehavior).toBe('append');
});

it('allows non-string values for call arguments', () => {
const calls = [{name: 'status', value: 1}];
const rangeBehavior = getRangeBehavior(rangeBehaviors, calls);
expect(rangeBehavior).toBe('refetch');
});
});

describe('when rangeBehaviors are a plain object', () => {
Expand Down
15 changes: 4 additions & 11 deletions src/mutation/getRangeBehavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import type {
Call,
CallValue,
RangeBehaviors,
} from 'RelayInternalTypes';

Expand Down Expand Up @@ -67,18 +68,10 @@ function getRangeBehavior(
*/
function getObjectFromCalls(
calls: Array<Call>
): {[argName: string]: string} {
const behaviors = {};
): {[argName: string]: CallValue} {
const behaviors: {[argName: string]: CallValue} = {};
calls.forEach(call => {
const behavior = call.value;
invariant(
typeof behavior === 'string',
'getRangeBehavior(): Expected range behavior for key `%s` to be a ' +
'string, got `%s`.',
call.name,
behavior
);
behaviors[call.name] = behavior;
behaviors[call.name] = call.value;
});
return behaviors;
}
Expand Down
2 changes: 1 addition & 1 deletion src/tools/RelayInternalTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export type UpdateOptions = {
};

type RangeBehaviorsFunction = (
connectionArgs: {[argName: string]: string},
connectionArgs: {[argName: string]: CallValue},
) => $Keys<GraphQLMutatorConstants.RANGE_OPERATIONS>;

type RangeBehaviorsObject = {
Expand Down

0 comments on commit c9fb0e8

Please sign in to comment.