SonS
Convex Community2y ago
18 replies
Son

How to use useMutation with convex-ents. API object TYPE error

in my frontend i'm calling this api

const storeUser = useMutation(api.users.store);

but i get this type error. the function still runs and works as expected.

Property 'users' does not exist on type '{ clerkBackend: { AdminGetUserList: FunctionReference<"action", "public", {}, { id: string; email: string | undefined; firstName: string | null; }[] | null>; }; messageActions: { ...; }; }'

it cannot find the api because i have replaced...

// import { mutation, query } from './_generated/server';

with

import { mutation } from './functions';

this is part of my functions.ts

import { entsTableFactory } from 'convex-ents';
import {
  customCtx,
  customMutation,
  customQuery
} from 'convex-helpers/server/customFunctions';
import { GenericDatabaseReader, GenericDatabaseWriter } from 'convex/server';
import { DataModel } from './_generated/dataModel';
import {
  internalMutation as baseInternalMutation,
  internalQuery as baseInternalQuery,
  mutation as baseMutation,
  query as baseQuery
} from './_generated/server';
import { entDefinitions } from './schema';
import { MutationCtx } from './types';

type LegacyTables = 'messages' | 'emailList' | 'users';

export const query = customQuery(
  baseQuery,
  customCtx(async (ctx) => {
    return {
      table: entsTableFactory(ctx, entDefinitions),
      db: ctx.db as unknown as GenericDatabaseReader<
        Pick<DataModel, LegacyTables>
      >
    };
  })
);

export const mutation = customMutation(
  baseMutation,
  customCtx(async (ctx) => {
    return {
      table: entsTableFactory(ctx, entDefinitions),
      db: ctx.db as GenericDatabaseWriter<Pick<DataModel, LegacyTables>>
    };
  })
);


how can i fix this? As soon as put this back in

`// import { mutation, query } from './_generated/server';
`

everything works.
Was this page helpful?