Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
yaacovCR committed Jul 12, 2021
1 parent 9309291 commit 31ed61a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/batch-delegate/tests/withTransforms.test.ts
Expand Up @@ -73,7 +73,7 @@ describe('works with complex transforms', () => {
]
}),
resultTransformer: (results, delegationContext) => {
const userIds = delegationContext.args['userIds'];
const userIds = delegationContext.args?.['userIds'];
const booksByUserIds = results.reduce(
(acc: any, { userId, books }: { userId: string, books: any[] }) => {
acc[userId] = books
Expand Down
Expand Up @@ -51,7 +51,7 @@ function addVariablesToRootField(
variables: Record<string, any>;
} {
const document = originalRequest.document;
const variableValues = originalRequest.variables;
const variableValues = originalRequest.variables ?? {};

const operations: Array<OperationDefinitionNode> = document.definitions.filter(
def => def.kind === Kind.OPERATION_DEFINITION
Expand Down
18 changes: 10 additions & 8 deletions packages/delegate/src/transforms/FilterToSchema.ts
Expand Up @@ -41,7 +41,7 @@ export default class FilterToSchema implements Transform {
function filterToSchema(
targetSchema: GraphQLSchema,
document: DocumentNode,
variables: Record<string, any>
variables?: Record<string, any>
): { document: DocumentNode; variables: Record<string, any> } {
const operations: Array<OperationDefinitionNode> = document.definitions.filter(
def => def.kind === Kind.OPERATION_DEFINITION
Expand Down Expand Up @@ -105,13 +105,15 @@ function filterToSchema(
});
}

const newVariables = usedVariables.reduce((acc, variableName) => {
const variableValue = variables[variableName];
if (variableValue !== undefined) {
acc[variableName] = variableValue;
}
return acc;
}, {});
const newVariables = variables
? usedVariables.reduce((acc, variableName) => {
const variableValue = variables[variableName];
if (variableValue !== undefined) {
acc[variableName] = variableValue;
}
return acc;
}, {})
: {};

return {
document: {
Expand Down

0 comments on commit 31ed61a

Please sign in to comment.