Array of Objects Apollo Server and post from react

一世执手 提交于 2019-11-28 14:35:16

You can only use input types for input (GraphQLInputObjectType) and object types for output (GraphQLObjectType). You are using Specials as both: As output type for the field specials in ShoppingItem and as input type in mutation argument specials. To do this you need two types. The reason for this is that output types (can) have resolvers (this is actually abstracted away from apollo server in your case). You will have to create two different types:

type ShoppingItem {
    description: String
    specials: [Specials]
}

type Specials {
    description: String
    price: String
    qty: String
    saved: String
}

input SpecialsDraft {
    description: String
    price: String
    qty: String
    saved: String
}

type Mutation {
    saveNewItem(description: String!, specials: [SpecialsDraft]) : ShoppingItem
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!