Skip to content

Batch delegation memoization is insensitive to non-key arguments #5188

@maxbol

Description

@maxbol

Issue workflow progress

Progress of the issue based on the Contributor Workflow

  • 1. The issue provides a reproduction available on Github, Stackblitz or CodeSandbox

    Make sure to fork this template and run yarn generate in the terminal.

    Please make sure the GraphQL Tools package versions under package.json matches yours.

  • 2. A failing test has been provided
  • 3. A local solution has been provided
  • 4. A pull request is pending review

Describe the bug

When using batchDelegateToSchema, the cacheKey for fetching a memoized loader is created using either the requested field name (for fields returning scalars) or the field name + selection set (for fields returning composites). When using this in conjunction with non-key arguments (for instance via argsFromKeys), those arguments do not effect the cacheKey. Thus, delegating the same field multiple times with different arguments only ever result in one delegation.

Possible solution is to use the entire field node (with alias redacted) instead of only the selection set when creating the cache key. This seems to solve the problem, afaik (see related PR).

#5189

To Reproduce
Steps to reproduce the behavior:

See unit tests in related pull request.

Expected behavior

Delegate resolvers should run once for every set of non-key arguments passed to batchDelegateToSchema.

Environment:

  • OS:
  • @graphql-tools/batch-delegate: 8.4.25
  • NodeJS: v16.13.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions