【发布时间】:2020-05-04 17:14:01
【问题描述】:
我们使用https://github.com/MichalLytek/type-graphql 来定义我们的graphql 模式当我们序列化原始打字稿实体对象时,这不尊重我们GQL 实体中的各种字段注释并最终泄漏不需要的数据。 Profile实体类下面的示例
import { Field, Int, ObjectType } from 'type-graphql'
import { Column, Entity, ManyToOne, OneToMany } from 'typeorm'
import { Account } from '../account/account.entity'
export class Profile {
@Field()
@Column({ unique: true })
public username: string
@Field()
@Column()
public name: string
// Relations
@Column()
public accountId: string
@ManyToOne(type => Account, account => account.profiles, { eager: true })
public account: Account
}
account 包含敏感数据。当我们 JSON.stringify 配置文件引用时,我们不希望帐户输出。帐户未使用 @Field 注释,我们预计不会输出。
【问题讨论】:
标签: node.js typescript graphql apollo-server