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

Pass call type in from/toGraphQL #1257

Closed
wants to merge 6 commits 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
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ describe('transformPayloadToRelayGraphMode()', () => {
},
{
op: 'putEdges',
args: [{name: 'first', value: '1'}, {name: 'orderby', value: 'date'}],
args: [{name: 'first', value: '1', type: null}, {name: 'orderby', value: 'date', type: null}],
edges: [
{
__typename: 'CommentsEdge',
Expand Down
13 changes: 13 additions & 0 deletions src/query/__tests__/RelayQuery-getCallsWithValues-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ describe('RelayQueryNode.prototype.getCallsWithValues()', function() {
expect(field.getCallsWithValues()).toEqual([{
name: 'size',
value: null,
type: null,
}]);
});

Expand All @@ -44,6 +45,7 @@ describe('RelayQueryNode.prototype.getCallsWithValues()', function() {
expect(field.getCallsWithValues()).toEqual([{
name: 'size',
value: 32,
type: null,
}]);
});
});
Expand All @@ -56,6 +58,7 @@ describe('RelayQueryNode.prototype.getCallsWithValues()', function() {
expect(field.getCallsWithValues()).toEqual([{
name: 'size',
value: null,
type: null,
}]);
});

Expand All @@ -66,6 +69,7 @@ describe('RelayQueryNode.prototype.getCallsWithValues()', function() {
expect(field.getCallsWithValues()).toEqual([{
name: 'size',
value: [],
type: null,
}]);
});

Expand All @@ -76,6 +80,7 @@ describe('RelayQueryNode.prototype.getCallsWithValues()', function() {
expect(field.getCallsWithValues()).toEqual([{
name: 'size',
value: 32,
type: null,
}]);
});

Expand All @@ -86,6 +91,7 @@ describe('RelayQueryNode.prototype.getCallsWithValues()', function() {
expect(field.getCallsWithValues()).toEqual([{
name: 'size',
value: [32],
type: null,
}]);
});
});
Expand All @@ -98,6 +104,7 @@ describe('RelayQueryNode.prototype.getCallsWithValues()', function() {
expect(field.getCallsWithValues()).toEqual([{
name: 'size',
value: [],
type: null,
}]);
});

Expand All @@ -108,6 +115,7 @@ describe('RelayQueryNode.prototype.getCallsWithValues()', function() {
expect(field.getCallsWithValues()).toEqual([{
name: 'size',
value: [64],
type: null,
}]);
});
});
Expand All @@ -121,6 +129,7 @@ describe('RelayQueryNode.prototype.getCallsWithValues()', function() {
expect(field.getCallsWithValues()).toEqual([{
name: 'size',
value: [null],
type: null,
}]);
});

Expand All @@ -132,6 +141,7 @@ describe('RelayQueryNode.prototype.getCallsWithValues()', function() {
expect(field.getCallsWithValues()).toEqual([{
name: 'size',
value: [[]],
type: null,
}]);
});

Expand All @@ -143,6 +153,7 @@ describe('RelayQueryNode.prototype.getCallsWithValues()', function() {
expect(field.getCallsWithValues()).toEqual([{
name: 'size',
value: [32],
type: null,
}]);
});

Expand All @@ -154,6 +165,7 @@ describe('RelayQueryNode.prototype.getCallsWithValues()', function() {
expect(field.getCallsWithValues()).toEqual([{
name: 'size',
value: [[32]],
type: null,
}]);
});

Expand All @@ -168,6 +180,7 @@ describe('RelayQueryNode.prototype.getCallsWithValues()', function() {
expect(field.getCallsWithValues()).toEqual([{
name: 'size',
value: [32, 64],
type: null,
}]);
});
});
Expand Down
17 changes: 9 additions & 8 deletions src/query/__tests__/RelayQuery-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ describe('RelayQuery', () => {
{identifyingArgName: 'id'}
);
expect(root.getCallsWithValues()).toEqual([
{name: 'id', value: '123'},
{name: 'id', value: '123', type: null},
]);
});

Expand Down Expand Up @@ -138,6 +138,7 @@ describe('RelayQuery', () => {
expect(root.getIdentifyingArg()).toEqual({
name: 'id',
value: '123',
type: null,
});
});

Expand Down Expand Up @@ -308,7 +309,7 @@ describe('RelayQuery', () => {
type: 'ProfilePicture',
});
expect(field.getCallsWithValues()).toEqual([
{name: 'size', value: 32},
{name: 'size', value: 32, type: null},
]);
field = RelayQuery.Field.build({
fieldName: 'profilePicture',
Expand All @@ -319,7 +320,7 @@ describe('RelayQuery', () => {
type: 'ProfilePicture',
});
expect(field.getCallsWithValues()).toEqual([
{name: 'size', value: ['32']},
{name: 'size', value: ['32'], type: null},
]);
});

Expand All @@ -336,7 +337,7 @@ describe('RelayQuery', () => {
type: 'ProfilePicture',
});
expect(field.getDirectives()).toEqual([{
args: [{name: 'bar', value: 'baz'}],
args: [{name: 'bar', value: 'baz', type: null}],
name: 'foo',
}]);
});
Expand Down Expand Up @@ -377,7 +378,7 @@ describe('RelayQuery', () => {
expect(mutation.getChildren().length).toBe(1);
expect(mutation.getChildren()[0]).toBe(field);
expect(mutation.getCall())
.toEqual({name: 'feedback_like', value: {feedback_id:'123'}});
.toEqual({name: 'feedback_like', value: {feedback_id:'123'}, type: null});
expect(mutation.getCallVariableName()).toEqual('input');
expect(mutation.getRoute().name).toBe('FooRoute');
});
Expand All @@ -401,7 +402,7 @@ describe('RelayQuery', () => {
expect(mutation.getChildren().length).toBe(1);
expect(mutation.getChildren()[0]).toBe(field);
expect(mutation.getCall())
.toEqual({name: 'feedback_like', value: ''});
.toEqual({name: 'feedback_like', value: '', type: null});
expect(mutation.getCallVariableName()).toEqual('input');
});
});
Expand Down Expand Up @@ -483,7 +484,7 @@ describe('RelayQuery', () => {
expect(grandchildren[0].getSchemaName()).toBe('id');
expect(grandchildren[1].getSchemaName()).toBe('profilePicture');
expect(grandchildren[1].getCallsWithValues()).toEqual([
{name: 'size', value: 'override'},
{name: 'size', value: 'override', type: null},
]);
});

Expand Down Expand Up @@ -533,7 +534,7 @@ describe('RelayQuery', () => {
expect(grandchildren[0].getSchemaName()).toBe('id');
expect(grandchildren[1].getSchemaName()).toBe('profilePicture');
expect(grandchildren[1].getCallsWithValues()).toEqual([
{name: 'size', value: 'override'},
{name: 'size', value: 'override', type: null},
]);

expect(children[2] instanceof RelayQuery.Fragment);
Expand Down
29 changes: 17 additions & 12 deletions src/query/__tests__/RelayQueryField-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ describe('RelayQueryField', () => {
null,
undefined,
],
type: null,
},
]);
});
Expand Down Expand Up @@ -363,7 +364,7 @@ describe('RelayQueryField', () => {
Relay.QL`fragment on User { friends(first:"10",isViewerFriend:true) }`
).getChildren()[0];
expect(connectionField.getRangeBehaviorCalls())
.toEqual([{name: 'isViewerFriend', value: true}]);
.toEqual([{name: 'isViewerFriend', value: true, type: null}]);
});

it('throws for non-connection fields', () => {
Expand All @@ -385,6 +386,7 @@ describe('RelayQueryField', () => {
expect(ifFalse.getRangeBehaviorCalls()).toEqual([{
name: 'if',
value: false,
type: null,
}]);
});

Expand All @@ -395,6 +397,7 @@ describe('RelayQueryField', () => {
expect(unlessTrue.getRangeBehaviorCalls()).toEqual([{
name: 'unless',
value: true,
type: null,
}]);

const unlessFalse = getNode(Relay.QL`
Expand All @@ -413,6 +416,7 @@ describe('RelayQueryField', () => {
expect(friendsScalar.getRangeBehaviorCalls()).toEqual([{
name: 'isViewerFriend',
value: false,
type: null,
}]);

const friendsVariableRQL = Relay.QL`
Expand All @@ -424,6 +428,7 @@ describe('RelayQueryField', () => {
expect(friendsVariable.getRangeBehaviorCalls()).toEqual([{
name: 'isViewerFriend',
value: false,
type: null,
}]);
});
});
Expand Down Expand Up @@ -620,14 +625,14 @@ describe('RelayQueryField', () => {
it('returns arguments with values', () => {
// scalar values are converted to strings
expect(friendsScalarField.getCallsWithValues()).toEqual([
{name: 'first', value: '10'},
{name: 'after', value: 'offset'},
{name: 'orderby', value: 'name'},
{name: 'first', value: '10', type: null},
{name: 'after', value: 'offset', type: null},
{name: 'orderby', value: 'name', type: null},
]);
// variables return their values
expect(friendsVariableField.getCallsWithValues()).toEqual([
{name: 'first', value: 10},
{name: 'after', value: 'offset'},
{name: 'first', value: 10, type: null},
{name: 'after', value: 'offset', type: null},
]);

const pictureScalarRQL = Relay.QL`
Expand All @@ -637,7 +642,7 @@ describe('RelayQueryField', () => {
`;
const pictureScalar = getNode(pictureScalarRQL).getChildren()[0];
expect(pictureScalar.getCallsWithValues()).toEqual([
{name: 'size', value: ['32', '64']},
{name: 'size', value: ['32', '64'], type: null},
]);

const pictureVariableRQL = Relay.QL`
Expand All @@ -652,7 +657,7 @@ describe('RelayQueryField', () => {
const pictureVariable =
getNode(pictureVariableRQL, variables).getChildren()[0];
expect(pictureVariable.getCallsWithValues()).toEqual([
{name: 'size', value: [32, '64']},
{name: 'size', value: [32, '64'], type: null},
]);
});

Expand All @@ -664,7 +669,7 @@ describe('RelayQueryField', () => {
}
`, variables).getChildren()[0];
expect(profilePicture.getCallsWithValues()).toEqual(
[{name: 'size', value: [32, 64]}]
[{name: 'size', value: [32, 64], type: null}]
);
});

Expand All @@ -685,8 +690,8 @@ describe('RelayQueryField', () => {
clonedFeed = friendsVariableField.cloneFieldWithCalls(
friendsVariableField.getChildren(),
[
{name: 'first', value: 10},
{name: 'after', value: 'offset'},
{name: 'first', value: 10, type: null},
{name: 'after', value: 'offset', type: null},
]
);
expect(clonedFeed).toBe(friendsVariableField);
Expand Down Expand Up @@ -792,7 +797,7 @@ describe('RelayQueryField', () => {
expect(field.getDirectives()).toEqual([
{
args: [
{name: 'if', value: true},
{name: 'if', value: true, type: null},
],
name: 'include',
},
Expand Down
2 changes: 1 addition & 1 deletion src/query/__tests__/RelayQueryFragment-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ describe('RelayQueryFragment', () => {
expect(fragment.getDirectives()).toEqual([
{
args: [
{name: 'if', value: true},
{name: 'if', value: true, type: null},
],
name: 'include',
},
Expand Down
1 change: 1 addition & 0 deletions src/query/__tests__/RelayQueryMutation-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ describe('RelayQueryMutation', () => {
expect(mutationQuery.getCall()).toEqual({
name: 'commentCreate',
value: input,
type: null,
});
const children = mutationQuery.getChildren();
expect(children.length).toBe(2);
Expand Down
4 changes: 2 additions & 2 deletions src/query/__tests__/RelayQueryRoot-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ describe('RelayQueryRoot', () => {
expect(me.getIdentifyingArg()).toEqual(undefined);

expect(usernames.getIdentifyingArg()).toEqual(
{name: 'names', value: 'mroch'}
{name: 'names', value: 'mroch', type: '[String!]!'}
);

expect(getNode(Relay.QL`
Expand Down Expand Up @@ -441,7 +441,7 @@ describe('RelayQueryRoot', () => {
expect(query.getDirectives()).toEqual([
{
args: [
{name: 'if', value: true},
{name: 'if', value: true, type: null},
],
name: 'include',
},
Expand Down
2 changes: 1 addition & 1 deletion src/query/__tests__/buildRQL-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ describe('buildRQL', () => {
expect(children[1].getSchemaName()).toBe('profilePicture');
// Variable has the applied value, not initial value.
expect(children[1].getCallsWithValues()).toEqual([
{name: 'size', value: '32'},
{name: 'size', value: '32', type: null},
]);
});

Expand Down
4 changes: 4 additions & 0 deletions src/query/__tests__/callsToGraphQL-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ describe('callsToGraphQL', function() {
const relayCalls = [{
name: 'size',
value: null,
type: null,
}];
const graphqlCalls = [RelayTestUtils.createCall('size', null)];
expect(callsFromGraphQL(graphqlCalls)).toEqual(relayCalls);
Expand All @@ -33,6 +34,7 @@ describe('callsToGraphQL', function() {
const relayCalls = [{
name: 'size',
value: [],
type: null,
}];
const graphqlCalls = [RelayTestUtils.createCall('size', [])];
expect(callsFromGraphQL(graphqlCalls)).toEqual(relayCalls);
Expand All @@ -43,6 +45,7 @@ describe('callsToGraphQL', function() {
const relayCalls = [{
name: 'size',
value: [32, 64],
type: null,
}];
const graphqlCalls = [RelayTestUtils.createCall('size', [32, 64])];
expect(callsFromGraphQL(graphqlCalls)).toEqual(relayCalls);
Expand All @@ -53,6 +56,7 @@ describe('callsToGraphQL', function() {
const relayCalls = [{
name: 'size',
value: 32,
type: null,
}];
const graphqlCalls = [RelayTestUtils.createCall('size', 32)];
expect(callsFromGraphQL(graphqlCalls)).toEqual(relayCalls);
Expand Down
2 changes: 1 addition & 1 deletion src/query/__tests__/createRelayQuery-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('createRelayQuery', () => {
);
expect(root instanceof RelayQuery.Root).toBe(true);
expect(root.getFieldByStorageKey('newsFeed').getCallsWithValues()).toEqual(
[{name: 'first', value: 10}]
[{name: 'first', value: 10, type: null}]
);
});
});
Loading