-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
feat: add missing updateMany and deleteMany resolvers on flexible backend #2758
Conversation
…kend Co-authored-by: v1b3m <vibenjamin6@gmail.com>
server/src/workspace/workspace-resolver-builder/factories/update-many-resolver.factory.ts
Show resolved
Hide resolved
@@ -21,6 +21,10 @@ export const getResolverName = ( | |||
return `update${pascalCase(objectMetadata.nameSingular)}`; | |||
case 'deleteOne': | |||
return `delete${pascalCase(objectMetadata.nameSingular)}`; | |||
case 'updateMany': | |||
return `updateMany${pascalCase(objectMetadata.namePlural)}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gitstart-twenty Juste use the name plural without the Many
return `updateMany${pascalCase(objectMetadata.namePlural)}`; | |
return `update${pascalCase(objectMetadata.namePlural)}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay
case 'updateMany': | ||
return `updateMany${pascalCase(objectMetadata.namePlural)}`; | ||
case 'deleteMany': | ||
return `deleteMany${pascalCase(objectMetadata.namePlural)}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return `deleteMany${pascalCase(objectMetadata.namePlural)}`; | |
return `delete${pascalCase(objectMetadata.namePlural)}`; |
server/src/workspace/workspace-query-builder/factories/update-many-query.factory.ts
Show resolved
Hide resolved
result, | ||
targetTableName, | ||
'update', | ||
)?.records[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gitstart-twenty It's a many
query, so we should directly return records and not the first element of the array.
)?.records[0]; | |
)?.records; |
result, | ||
targetTableName, | ||
'deleteFrom', | ||
)?.records[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
)?.records[0]; | |
)?.records; |
>( | ||
args: DeleteManyResolverArgs<Filter>, | ||
options: WorkspaceQueryRunnerOptions, | ||
): Promise<Record | undefined> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
): Promise<Record | undefined> { | |
): Promise<Record[] | undefined> { |
async updateMany<Record extends IRecord = IRecord>( | ||
args: UpdateManyResolverArgs<Record>, | ||
options: WorkspaceQueryRunnerOptions, | ||
): Promise<Record | undefined> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
): Promise<Record | undefined> { | |
): Promise<Record[] | undefined> { |
server/src/workspace/workspace-resolver-builder/factories/update-many-resolver.factory.ts
Show resolved
Hide resolved
...src/workspace/workspace-resolver-builder/interfaces/workspace-resolvers-builder.interface.ts
Show resolved
Hide resolved
server/src/workspace/workspace-schema-builder/utils/get-resolver-args.util.ts
Show resolved
Hide resolved
Co-authored-by: v1b3m <vibenjamin6@gmail.com>
@magrinj Just one question, where are the return types for these auto-generated resolvers defined? Where do I specify that |
When you check the return types of the mutations, you notice that not a single one returns an array(list) of items, all just return one item. For a quick example, even the |
@magrinj I've noticed the output types are defined in |
In --- root-type.factory.ts 2023-11-30 09:54:52
+++ root-type.factory.new.ts 2023-11-30 09:54:37
@@ -9,6 +9,7 @@
import { TypeDefinitionsStorage } from 'src/workspace/workspace-schema-builder/storages/type-definitions.storage';
import { getResolverName } from 'src/workspace/utils/get-resolver-name.util';
import { getResolverArgs } from 'src/workspace/workspace-schema-builder/utils/get-resolver-args.util';
+import { TypeMapperService } from 'src/workspace/workspace-schema-builder/services/type-mapper.service';
import { ArgsFactory } from './args.factory';
import { ObjectTypeDefinitionKind } from './object-type-definition.factory';
@@ -25,6 +26,7 @@
constructor(
private readonly typeDefinitionsStorage: TypeDefinitionsStorage,
+ private readonly typeMapperService: TypeMapperService,
private readonly argsFactory: ArgsFactory,
) {}
@@ -70,7 +72,7 @@
for (const methodName of workspaceResolverMethodNames) {
const name = getResolverName(objectMetadata, methodName);
const args = getResolverArgs(methodName);
- const outputType = this.typeDefinitionsStorage.getObjectTypeByKey(
+ const objectType = this.typeDefinitionsStorage.getObjectTypeByKey(
objectMetadata.id,
methodName === 'findMany'
? ObjectTypeDefinitionKind.Connection
@@ -84,7 +86,7 @@
options,
);
- if (!outputType) {
+ if (!objectType) {
this.logger.error(
`Could not find a GraphQL type for ${objectMetadata.id} for method ${methodName}`,
{
@@ -99,6 +101,10 @@
);
}
+ const outputType = this.typeMapperService.mapToGqlType(objectType, {
+ isArray: ['updateMany', 'deleteMany'].includes(methodName),
+ });
+
fieldConfigMap[name] = {
type: outputType,
args: argsType, |
Good catch on that, I guess it's an issue, if you can fix it and update the above patch to include |
Co-authored-by: v1b3m <vibenjamin6@gmail.com>
Hey @magrinj, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job, thanks for your work !
Fixes #2721