0

I'm trying to make a mutation in type-graphql and one of the arguments is Object so:

@Mutation(() => Boolean)
async createProduct(
    @Arg('name', () => String) name: string,
    @Arg('price', () => Int) price: number,
    @Arg('images', () => [InputImages]) images: [ImagesArray],
) {
    // Code
}

So i made an input type for argument "images":

@InputType()
class InputImages {
  @Field(() => String)
  filename: string;
}

And an Object type:

@ObjectType()
export class ImagesArray {
    @Field(() => String)
    filename: string
}

Now i am trying to use GraphQL Code Generator and i need to write queries and mutations on client side as a .graphql file extension, so i have:

mutation CreateProduct(
    $name: String!
    $price: Int!
    $images: [ImagesArray]!
) {
    createProduct(
        name: $name
        price: $price
        images: $images
    );
}

And now when i try to run "npm run gen" says:

GraphQLDocumentError: Unknown type "ImagesArray".

I tried to add on top:

type ImagesArray {
    filename: String
}

Does not work again, any idea?

Carlo Corradini
  • 2,927
  • 2
  • 18
  • 24
Ardian
  • 39
  • 1
  • 7

1 Answers1

0
  1. You don't need ImagesArray type in args:
@Arg('images', () => [InputImages]) images: InputImages[],
  1. Update your mutation type name:
mutation CreateProduct(
    $name: String!
    $price: Int!
    $images: [InputImages!]!
) {
  # ...
}
Michał Lytek
  • 10,577
  • 3
  • 16
  • 24