Skip to content

Commit

Permalink
Fix resolvers to accept and move forward args with zero or false valu…
Browse files Browse the repository at this point in the history
…es (#586)

Fixing the args with zero value or false
  • Loading branch information
renatobenks authored and freiksenet committed Jan 23, 2018
1 parent 72ac16f commit 03ad432
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 24 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

### vNEXT

* ...
* Fix `delegateToSchema.js` to accept and move forward args with zero or false values [PR #586](https://github.com/apollographql/graphql-tools/pull/586)

### v2.18.0

Expand Down
15 changes: 6 additions & 9 deletions src/stitching/delegateToSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,15 @@ export default async function delegateToSchema(
if (
operationDefinition &&
operationDefinition.kind === Kind.OPERATION_DEFINITION &&
operationDefinition.variableDefinitions
operationDefinition.variableDefinitions &&
Array.isArray(operationDefinition.variableDefinitions)
) {
operationDefinition.variableDefinitions.forEach(definition => {
for (const definition of operationDefinition.variableDefinitions) {
const key = definition.variable.name.value;
// (XXX) This is kinda hacky
let actualKey = key;
if (actualKey.startsWith('_')) {
actualKey = actualKey.slice(1);
}
const value = args[actualKey] || args[key] || info.variableValues[key];
variableValues[key] = value;
});
const actualKey = key.startsWith('_') ? key.slice(1) : key;
variableValues[key] = args[actualKey] != null ? args[actualKey] : info.variableValues[key];
}
}

if (operation === 'query' || operation === 'mutation') {
Expand Down
28 changes: 14 additions & 14 deletions src/test/testMergeSchemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1143,21 +1143,21 @@ bookingById(id: "b1") {
describe('variables', () => {
it('basic', async () => {
const propertyFragment = `
propertyById(id: $p1) {
id
name
}
`;
propertyById(id: $p1) {
id
name
}
`;
const bookingFragment = `
bookingById(id: $b1) {
id
customer {
name
}
startTime
endTime
}
`;
bookingById(id: $b1) {
id
customer {
name
}
startTime
endTime
}
`;

const propertyResult = await graphql(
propertySchema,
Expand Down

0 comments on commit 03ad432

Please sign in to comment.