diff --git a/CHANGELOG.md b/CHANGELOG.md index c5330fd85c4..326a2a06008 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/stitching/delegateToSchema.ts b/src/stitching/delegateToSchema.ts index f8214167e03..4e64f7a67f6 100644 --- a/src/stitching/delegateToSchema.ts +++ b/src/stitching/delegateToSchema.ts @@ -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') { diff --git a/src/test/testMergeSchemas.ts b/src/test/testMergeSchemas.ts index cce1678ceb5..34b5d734951 100644 --- a/src/test/testMergeSchemas.ts +++ b/src/test/testMergeSchemas.ts @@ -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,