Packages

@graphql-tools/batch-delegate

10.1.7 · 20 Nov 2026MIT753.6k / weekRepositorynpmAtom feed

Your version

9.0.27

2 Jan 2025Where it was published

9.0.41 is the newest release of 9.x.

In short

1 fixed

Release note

The section about @graphql-tools/batch-delegate of a note shared by several packages.

Patch Changes

  • Memoize the key arguments correctly;

    With the following schema and resolvers, userById should batch all the requests to usersByIds;

    {
          typeDefs: /* GraphQL */ `
            type User {
              id: ID!
              email: String!
            }
            type Query {
              userById(id: ID!): User
              usersByIds(ids: [ID!]): [User]
            }
          `,
          resolvers: {
            Query: {
              usersByIds: (_root, args) => {
                return args.ids.map((id: string) => users.find((user) => user.id === id));
              },
              userById: (root, args, context, info) => {
                return batchDelegateToSchema({
                  schema: userSubschema,
                  fieldName: 'usersByIds',
                  key: args.id,
                  rootValue: root,
                  context,
                  info,
                })
              },
            },
          },
        }

    This query should batch all the requests to usersByIds:

    {
      userById(id: "1") {
        id
        email
      }
      userById(id: "2") {
        id
        email
      }
    }

    The delegation request should be;

    {
      usersByIds(ids: ["1", "2"]) {
        id
        email
      }
    }

A whole project to check? Paste its package.json in the dependency check: every deprecated, outdated or vulnerable dependency, with what to upgrade to. Free, no account.