-
(Reposting from here) I'm trying to add an additional field to the 'createOneX' input that is not stored with the entity: import { Field, InputType } from '@nestjs/graphql';
import { CreateOneInputType } from '@ptc-org/nestjs-query-graphql';
import { AssetDTO } from '../asset.dto';
@InputType('CreateOneAssetInput')
export class CreateOneAssetInputDTO extends CreateOneInputType(
'asset',
AssetDTO,
) {
@Field(() => String)
filePath: string;
}
type CreateOneAssetInput {
asset: CreateAsset!
filePath: String!
} The query service looks like: export class AssetQueryService extends ProxyQueryService<
AssetEntity,
CreateOneAssetInputDTO
> {
fileRepository: Repository<FileEntity>;
constructor(
@InjectQueryService(AssetEntity)
service: QueryService<AssetEntity, CreateOneAssetInputDTO>,
@InjectRepository(FileEntity)
fileRepository: Repository<FileEntity>,
) {
super(service);
this.fileRepository = fileRepository;
}
async createOne(input: CreateOneAssetInputDTO): Promise<AssetEntity> {
const { filePath } = input;
const file = await this.fileRepository
.createQueryBuilder()
.insert()
.into(FileEntity)
.orIgnore()
.values({
location: filePath,
})
.updateEntity(false)
.execute();
// ... more stuff
return this.proxied.createOne(input);
}
} The problem I'm having is Am I going about this the right way? As always your help is appreciated! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 7 replies
-
Are you setting |
Beta Was this translation helpful? Give feedback.
Hi @abrenoch,
Sorry that it took me a while but I figured it out, the thing is that this is actually expected behavior. What you could do is use the normal TypeORMQueryService (or keep what you have, but update it to receive
DeepPartial<AssetEntity>
) and add the following to theAssetModel
Here you can update the input (that is send the service), do checks etc.