graphql-tools icon indicating copy to clipboard operation
graphql-tools copied to clipboard

Batch delegation memoization is insensitive to non-key arguments

Open maxbol opened this issue 2 years ago • 1 comments
trafficstars

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).

https://github.com/ardatan/graphql-tools/pull/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

maxbol avatar Apr 18 '23 13:04 maxbol

Has anyone been able to have a look at this? Would love a fix - or a suggestion on how to move forward with implementation since my PR received a negative review. Right now we have to run a fork of batch-delegate which is not ideal

maxbol avatar Dec 19 '23 14:12 maxbol