У меня есть input
для обновления блока. Я хочу, чтобы пользователи могли обновлять имя или контент или и то, и другое. Теперь проблема в том, что если я передаю только имя GrapQL, выдается ошибка типа Variable \"$updateBlockInput\" got invalid value { name: \"Updated again\" }; Field content of required type String! was not provided.
и Vice Varsa.
Что я делаю не так?
update-block.input.ts
import { InputType, Field } from '@nestjs/graphql';
import { IsOptional, IsNotEmpty } from 'class-validator';
@InputType()
export class UpdateBlockInput {
@IsOptional()
@IsNotEmpty()
@Field()
name?: string;
@IsOptional()
@IsNotEmpty()
@Field()
content?: string;
}
block.resolver.ts
...
@Mutation(returns => BlockType)
updateBlock(
@Args('id') id: string,
@Args('updateBlockInput') updateBlockInput: UpdateBlockInput,
) {
return this.blockService.update(id, updateBlockInput);
}
...
Мутация
mutation(
$id: String!
$updateBlockInput: UpdateBlockInput!
) {
updateBlock(
id: $id
updateBlockInput: $updateBlockInput
) {
name
content
}
}
Переменные
{
"id": "087e7c12-b48f-4ac4-ae76-1b9a96bbcbdc",
"updateBlockInput": {
"name": "Updated again"
}
}