Skip to content

Commit

Permalink
fix: handle default case when a resource cannot be pluralized
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mwillbanks authored and macrozone committed Nov 7, 2023
1 parent 0d9c77b commit dce98b1
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions packages/dataprovider/src/utils/makeIntrospectionOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down

0 comments on commit dce98b1

Please sign in to comment.