From dce98b140422f32526a74f16509aa04e5a446a34 Mon Sep 17 00:00:00 2001 From: Mike Willbanks Date: Thu, 15 Jun 2023 10:33:54 -0500 Subject: [PATCH] fix: handle default case when a resource cannot be pluralized When typegraphql-prisma cannot pluralize a word, it changes the query functions to not have a pluralized form and instead uses prefixes such as findMany and findUnique in front of those resources. This fix changes the default if we encounter one of those types of words. --- .../src/utils/makeIntrospectionOptions.ts | 35 +++++++++++++++---- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/packages/dataprovider/src/utils/makeIntrospectionOptions.ts b/packages/dataprovider/src/utils/makeIntrospectionOptions.ts index 8c8bdd9..083745e 100644 --- a/packages/dataprovider/src/utils/makeIntrospectionOptions.ts +++ b/packages/dataprovider/src/utils/makeIntrospectionOptions.ts @@ -41,13 +41,34 @@ export const makeIntrospectionOptions = (options: OurOptions) => { prefix(`${pluralize(camelCase(resource.name))}`), }, typegraphql: { - [GET_LIST]: (resource: Resource) => - prefix(`${pluralize(camelCase(resource.name))}`), - [GET_ONE]: (resource: Resource) => prefix(`${camelCase(resource.name)}`), - [GET_MANY]: (resource: Resource) => - prefix(`${pluralize(camelCase(resource.name))}`), - [GET_MANY_REFERENCE]: (resource: Resource) => - prefix(`${pluralize(camelCase(resource.name))}`), + [GET_LIST]: (resource: Resource) => { + const pluralName = pluralize(resource.name); + if (resource.name === pluralName) { + return prefix(`findMany${resource.name}`); + } + return prefix(`${pluralize(camelCase(resource.name))}`); + }, + [GET_ONE]: (resource: Resource) => { + const pluralName = pluralize(resource.name); + if (resource.name === pluralName) { + return prefix(`findUnique${resource.name}`); + } + return prefix(`${camelCase(resource.name)}`); + }, + [GET_MANY]: (resource: Resource) => { + const pluralName = pluralize(resource.name); + if (resource.name === pluralName) { + return prefix(`findMany${resource.name}`); + } + return prefix(`${pluralize(camelCase(resource.name))}`); + }, + [GET_MANY_REFERENCE]: (resource: Resource) => { + const pluralName = pluralize(resource.name); + if (resource.name === pluralName) { + return prefix(`findMany${resource.name}`); + } + return prefix(`${pluralize(camelCase(resource.name))}`); + }, }, ...options.queryOperationNames, };