Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: #117 handling noncount nouns / no plural forms by configuring operation names #118

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions packages/dataprovider/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,31 @@ useDataProvider({
})
```

## customize operation names:

This allows you to customize operation names for example when the names cannot
be pluralized (for one/many) or if you have custom operation names that you
would like to be called instead.

It will utilize the default operation names if one is not provided for any
particular key.

```

useDataProvider({
// ...
operationNames: {
RESOURCE_NAME: {
create: "myCreateOperation",
update: "myUpdateOperation",
delete: "myDeleteOperation",
one: "myFindOneOperation",
many: "myFindManyOperation",
},
},
})
```

## Usage with typegraphql-prisma

(beta)
Expand Down
5 changes: 5 additions & 0 deletions packages/dataprovider/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ export type ConfigOptions = {
};
customizeInputData?: CustomizeInputData;
introspection?: IntrospectionOptions;
operationNames?: {
[name: string]: {
[name: string]: string;
};
};
};

export type FetchType =
Expand Down
31 changes: 24 additions & 7 deletions packages/dataprovider/src/utils/makeIntrospectionOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,42 @@ export const makeIntrospectionOptions = (options: OurOptions) => {

const mutationOperationNames: Record<QueryDialect, object> = {
"nexus-prisma": {
[CREATE]: (resource: Resource) => prefix(`createOne${resource.name}`),
[UPDATE]: (resource: Resource) => prefix(`updateOne${resource.name}`),
[DELETE]: (resource: Resource) => prefix(`deleteOne${resource.name}`),
[CREATE]: (resource: Resource) =>
options?.operationNames?.[resource.name]?.create ||
prefix(`createOne${resource.name}`),
[UPDATE]: (resource: Resource) =>
options?.operationNames?.[resource.name]?.update ||
prefix(`updateOne${resource.name}`),
[DELETE]: (resource: Resource) =>
options?.operationNames?.[resource.name]?.delete ||
prefix(`deleteOne${resource.name}`),
},
typegraphql: {
[CREATE]: (resource: Resource) => prefix(`create${resource.name}`),
[UPDATE]: (resource: Resource) => prefix(`update${resource.name}`),
[DELETE]: (resource: Resource) => prefix(`delete${resource.name}`),
[CREATE]: (resource: Resource) =>
options?.operationNames?.[resource.name]?.create ||
prefix(`create${resource.name}`),
[UPDATE]: (resource: Resource) =>
options?.operationNames?.[resource.name]?.update ||
prefix(`update${resource.name}`),
[DELETE]: (resource: Resource) =>
options?.operationNames?.[resource.name]?.delete ||
prefix(`delete${resource.name}`),
},
};

return {
operationNames: {
[GET_LIST]: (resource: Resource) =>
options?.operationNames?.[resource.name]?.many ||
prefix(`${pluralize(camelCase(resource.name))}`),
[GET_ONE]: (resource: Resource) => prefix(`${camelCase(resource.name)}`),
[GET_ONE]: (resource: Resource) =>
options?.operationNames?.[resource.name]?.one ||
prefix(`${camelCase(resource.name)}`),
[GET_MANY]: (resource: Resource) =>
options?.operationNames?.[resource.name]?.many ||
prefix(`${pluralize(camelCase(resource.name))}`),
[GET_MANY_REFERENCE]: (resource: Resource) =>
options?.operationNames?.[resource.name]?.many ||
prefix(`${pluralize(camelCase(resource.name))}`),

...mutationOperationNames[options.queryDialect],
Expand Down