Skip to content

Commit

Permalink
Pass call type in from/toGraphQL
Browse files Browse the repository at this point in the history
Currently types are ignored and not getting passed in `callsFromGraphQL`
or `callsToGraphQL`.
This results in dangerous output in `toGraphQL`, in which all calls have
type null. This can cause problems when using non-scalar types (like
enum).
Example can be found
[here](facebook#1256).
  • Loading branch information
papigers committed Jul 3, 2016
1 parent 27bcf12 commit 8ee0ee7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/query/callsFromGraphQL.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const invariant = require('invariant');
type CallOrDirective = {
name: string,
value: ?ConcreteValue,
type?: ?string,
};

/**
Expand All @@ -43,6 +44,7 @@ function callsFromGraphQL(
for (let ii = 0; ii < callsOrDirectives.length; ii++) {
const callOrDirective = callsOrDirectives[ii];
let {value} = callOrDirective;
let {type} = callOrDirective.metadata;
if (value != null) {
if (Array.isArray(value)) {
value = value.map(arg => getCallValue(arg, variables));
Expand All @@ -53,7 +55,7 @@ function callsFromGraphQL(
value = getCallValue(value, variables);
}
}
orderedCalls.push({name: callOrDirective.name, value});
orderedCalls.push({name: callOrDirective.name, value, type});
}
return orderedCalls;
}
Expand Down
4 changes: 2 additions & 2 deletions src/query/callsToGraphQL.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ const QueryBuilder = require('QueryBuilder');
* Convert from plain object `{name, value}` calls to GraphQL call nodes.
*/
function callsToGraphQL(calls: Array<Call>): Array<ConcreteCall> {
return calls.map(({name, value}) => {
return calls.map(({name, value, type}) => {
let concreteValue = null;
if (Array.isArray(value)) {
concreteValue = value.map(QueryBuilder.createCallValue);
} else if (value != null) {
concreteValue = QueryBuilder.createCallValue(value);
}
return QueryBuilder.createCall(name, concreteValue);
return QueryBuilder.createCall(name, concreteValue, type);
});
}

Expand Down

0 comments on commit 8ee0ee7

Please sign in to comment.