问题描述
我正在尝试在 type-graphql 中进行更改,其中一个参数是 Object 所以:
@Mutation(() => Boolean)
async createProduct(
@Arg('name',() => String) name: string,@Arg('price',() => Int) price: number,@Arg('images',() => [Inputimages]) images: [ImagesArray],) {
// Code
}
所以我为参数“图像”创建了一个输入类型:
@InputType()
class Inputimages {
@Field(() => String)
filename: string;
}
还有一个对象类型:
@ObjectType()
export class ImagesArray {
@Field(() => String)
filename: string
}
现在我正在尝试使用 GraphQL 代码生成器,我需要在客户端编写查询和更改作为 .graphql 文件扩展名,所以我有:
mutation CreateProduct(
$name: String!
$price: Int!
$images: [ImagesArray]!
) {
createProduct(
name: $name
price: $price
images: $images
);
}
现在当我尝试运行 "npm run gen" 时说:
GraphQLDocumentError:未知类型“ImagesArray”。
我尝试在顶部添加:
type ImagesArray {
filename: String
}
不能再工作了,知道吗?
解决方法
- 您不需要输入
ImagesArray
参数:
@Arg('images',() => [InputImages]) images: InputImages[],
- 更新您的突变类型名称:
mutation CreateProduct(
$name: String!
$price: Int!
$images: [InputImages!]!
) {
# ...
}