簡體   English   中英

在 .graphql 文件中定義 GraphQL 對象類型不起作用

[英]Define GraphQL object type in .graphql files not working

我正在嘗試在 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
}

不能再工作了,有什么想法嗎?

  1. 在 args 中不需要ImagesArray類型:
@Arg('images', () => [InputImages]) images: InputImages[],
  1. 更新您的突變類型名稱:
mutation CreateProduct(
    $name: String!
    $price: Int!
    $images: [InputImages!]!
) {
  # ...
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM