Skip to content

Commit

Permalink
add prisma.listKey for InitialisedList
Browse files Browse the repository at this point in the history
  • Loading branch information
dcousens committed Mar 14, 2023
1 parent f0d4dc2 commit f353f63
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions packages/core/src/lib/core/types-for-lists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ export type InitialisedList = {
adminUILabels: { label: string; singular: string; plural: string; path: string };
cacheHint: ((args: CacheHintArgs) => CacheHint) | undefined;
listKey: string;
prisma: {
listKey: string;
};
ui: {
labelField: string;
searchFields: Set<string>;
Expand Down Expand Up @@ -240,7 +243,12 @@ function getListsWithInitialisedFields(
...getNamesFromList(listKey, list),
access: parseListAccessControl(list.access),
dbMap: list.db?.map,

prisma: {
listKey: listKey[0].toLowerCase() + listKey.slice(1),
},
extendPrismaSchema: list.db?.extendPrismaSchema,

types: listGraphqlTypes[listKey].types,
ui: {
labelField,
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/lib/core/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ export type PrismaClient = {
// Run prisma operations as part of a resolver
export async function runWithPrisma<T>(
context: KeystoneContext,
{ listKey }: InitialisedList,
{ prisma: { listKey } }: InitialisedList,
fn: (model: PrismaModel) => Promise<T>
) {
const model = context.prisma[listKey[0].toLowerCase() + listKey.slice(1)];
const model = context.prisma[listKey];
try {
return await fn(model);
} catch (err: any) {
Expand Down

0 comments on commit f353f63

Please sign in to comment.