Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix getRangeBehavior to allow non-string calls #1216

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/mutation/__tests__/getRangeBehavior-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ describe('getRangeBehavior()', () => {
const rangeBehavior = getRangeBehavior(rangeBehaviors, calls);
expect(rangeBehavior).toBe('append');
});

describe('when calls contain non-string values', () => {
it('returns the rangeBehavior for the calls', () => {
const calls = [{name: 'status', value: 1}];
const rangeBehavior = getRangeBehavior(rangeBehaviors, calls);
expect(rangeBehavior).toBe('refetch');
});
});
});

describe('when rangeBehaviors are a plain object', () => {
Expand Down
10 changes: 1 addition & 9 deletions src/mutation/getRangeBehavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,7 @@ function getObjectFromCalls(
): {[argName: string]: string} {
const behaviors = {};
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the return type of this function has to be changed to {[argName: string]: mixed}, since that's the type of call.value. not sure why flow isn't finding this.

});
return behaviors;
}
Expand Down