-
Notifications
You must be signed in to change notification settings - Fork 142
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
[Bug]: Defining additional UpdateDtos breaks Schema #72
Comments
Yep, I see the issue. In https://github.com/doug-martin/nestjs-query/blob/master/packages/query-graphql/src/types/update-one-input.type.ts#L23 we set the This would apply for all the create, update and delete types. Ill try to take a look at this over the next couple of days unless you want to tackle it. |
Dear @doug-martin , thanks for confirming this bug. Glad i did nothing wrong here 😄 Basically, you would change it to something liket his, right? @InputType()
export class CompleteTodoItemInputType extends UpdateOneInputType(
+ 'CompleteTodoItemInput',
TodoItemDTO,
CompleteTodoItemDTO
) {} Am I correct? |
@johannesschobel I'm working on this now. It looks like its going to be updated to @InputType()
export class CompleteTodoItemInputType extends UpdateOneInputType(
TodoItemDTO,
CompleteTodoItemDTO
) {} and the export function UpdateOneInputType<DTO, U extends DeepPartial<DTO>>(
DTOClass: Class<DTO>,
UpdateType: Class<U>,
): Class<UpdateOneInputType<DTO, U>> {
const metadataStorage = getMetadataStorage();
const existing = metadataStorage.getUpdateOneInputType<DTO, U>(DTOClass);
if (existing) {
return existing;
}
const { baseName } = getDTONames(DTOClass);
- @InputType(`UpdateOne${baseName}Input`)
+ @InputType({ isAbstract: true })
class UpdateOneInput implements UpdateOneInputType<DTO, U> {
@IsNotEmpty()
@Field(() => ID, { description: 'The id of the record to update' })
id!: string | number;
@Type(() => UpdateType)
@ValidateNested()
@Field(() => UpdateType, { description: 'The update to apply.' })
update!: U;
}
metadataStorage.addUpdateOneInputType(DTOClass, UpdateOneInput);
return UpdateOneInput;
}
|
@johannesschobel I've pushed up my changes to https://github.com/doug-martin/nestjs-query/tree/issue72 I'll finish cleaning up the docs and stuff tomorrow. I ended up changing the the export function UpdateOneInputType<U>(UpdateType: Class<U>): Class<UpdateOneInputType<U>> {
@InputType({ isAbstract: true })
class UpdateOneInput implements UpdateOneInputType<U> {
@IsNotEmpty()
@Field(() => ID, { description: 'The id of the record to update' })
id!: string | number;
@Type(() => UpdateType)
@ValidateNested()
@Field(() => UpdateType, { description: 'The update to apply.' })
update!: U;
}
return UpdateOneInput;
} Once I publish you should be able to just extend the type like so @InputType()
export class CompleteTodoItemInputType extends UpdateOneInputType( CompleteTodoItemDTO) {} And the graphql type will be named Let me know what you think and if I should make any additional changes. Stay safe and healthy! -Doug |
Dear @doug-martin , So basically - for the developer using your awesome library, nothing changes ;) All the best and stay safe, |
This is published under So your update type would change from @InputType()
export class CompleteTodoItemInputType extends UpdateOneInputType(TodoItemDTO, CompleteTodoItemDTO) {} To @InputType()
export class CompleteTodoItemInputType extends UpdateOneInputType(CompleteTodoItemDTO) {} Small change but still breaking. You can checkout the types documentation for more info. Thanks again for the bug report! |
Dear @doug-martin Can you please release the new version on npm? It has been tagged on GitHub but not released on NPM so far.. All the best and thank you very much for your time and effort working on this library! |
Sorry about that its published! |
you are awesome.. happy eastern - wish you all the best! |
Dear @doug-martin, |
Dear @doug-martin ,
while working on custom resolver methods, i stumbled upon an issue, i was able to reproduce in your example repository (shipped in this library).
You can take a look at the "how to reproduce" by looking at my commits here
master...johannesschobel:issue/update-dto
Description
I wanted to add a dedicated
completeTodoItem
mutation that only takes thecompleted
parameter. Note that the originalupdateTodoItem
also takes thename
, andcompleted
was set tooptional
. The dedicatedcompleteTodoItem
mutation should take this parameter as required.Input DTO
in order to provide sophisticated validationsInputType()
that uses this dtoMutation
in myResolver
that uses this newly createdInputType
.Note that i also committed the initial
schema.gql
file to see the actual changes in this file!As you can see, the new mutation is added correctly. Also, the newly created
InputType
as well as thedto
are added correctly. However, thedto
for the regularUpdateOneTodoItem
is also changed to this newly createddto
- which is, obviously, wrong.I hope you can reproduce the issue? Maybe i am doing something wrong here? As the docs were not quite accurate in this point, i was not sure if my approach is correct. I would be willing to document this feature, if we can figure out how to deal with the latter?
All the best and thanks for your time!
The text was updated successfully, but these errors were encountered: