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 resolvers to accept and move forward args with zero or false values #586

Merged
merged 11 commits into from
Jan 23, 2018
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