Can't resolve "Final argument to `executeLegacyOperation` must be a callback"

We are trying to upgrade to mongoDB 5.0 and have updated mongoose to 6.0.12. (Using mongodb driver 4.1.3) In running the batch tests (jest), we are stuck on the error message “Final argument to executeLegacyOperation must be a callback”

One example of a test that is failing:

    test('should update existing items and return UPDATED status', async () => {
        const {
            data: { upsertBatchRole },
        } = await gqlClient.fetch<{ upsertBatchRole: GQLUpsertBatchRoleOutput }>(upsertBatchRoleMutation, {
            condition: {},
            input: [
                {
                    name: 'new',
                    id: '57b418b8d03e63b856d86538',
                },
            ],
        });

        expect(upsertBatchRole).not.toBeNull();
        const { status, data } = upsertBatchRole as GQLUpsertBatchRoleOutput;

        const unitedData = uniteCategorizedArrays<GQLRole>({ ...data });

        expect(status).toBe(ms.UPDATED);
        expect(unitedData.length).toBe(1);
        expect(unitedData[0]).toHaveProperty('name');
        expect(unitedData[0]?.name).toBe('new');
        _.forEach(unitedData, (item) => {
            expect(item).toHaveProperty('id');
            expect(item).toHaveProperty('name');
        });

        const {
            data: { roleList },
        } = await gqlClient.fetch(`
            roleList {
                name
            }
        `);
        const orderedList = _.sortBy(roleList, 'name');
        expect(orderedList).toHaveLength(1);
        expect(orderedList[0].name).toBe('new');
    });

Currently, graphql is at 15.5.1. Tried to upgrade graphql and got as far as 15.8.0 as higher versions produced a different error. Current node version is 14.21.3

Not sure if graphql is the issue here so looking for any ideas on how to resolve the issue. Someone also suggested it might be the mutation code that calls Mongo as the likely source of the error.

Hey @Greg_Norkett,

Welcome to the MongoDB Community :sparkles:

Looking at the shared code snippet above, it’s quite difficult to debug without much information about the mongoose or the driver code. May I ask if you can share the entire stack trace or the code from where GraphQL is calling into mongoose?

Also, it seems that the last argument being passed should be a callback function, but it appears to be some other non-null value.

Thanks,
Kushagra