[英]GraphQL error: int() argument must be a string or a number, not 'list'
I have this mutation:我有这个突变:
export const SET_CART_MUTATION = gql`mutation setCartMutation($vendorSlug: String!, $sessionId: String, $productId:[Int!], $prices:[PriceInput]) {
setCart(vendorSlug: $vendorSlug, sessionId: $sessionId, productId:$productId, prices:$prices) {
cart {
${CART_FIELDS}
}
allTicketsAdded
}
}`
I want to create an array of productId but when I mutate: I get:我想创建一个 productId 数组,但是当我变异时:我得到:
Mutation error: Error: GraphQL error: int() argument must be a string or a number, not 'list'
My setCart class is:我的 setCart class 是:
class SetCart(graphene.Mutation):
class Arguments:
vendor_slug = graphene.String()
session_id = graphene.String()
product_id = graphene.List(graphene.Int)
prices = graphene.List(PriceInput)
Thanks for help, and ask questions.感谢您的帮助,并提出问题。
I solved it,我解决了,
If you have the same error and you're sure that's the mutation arguments are the same type as declared: the problem come from your mutation function:如果您有相同的错误并且您确定这是突变 arguments 与声明的类型相同:问题来自您的突变 function:
def mutate(self, info, vendor_slug, session_id, products, prices, participants):
# ? List of products given
products = Product.objects.get(id=product)
cart = Order.objects.get_cart(
vendor_slug, info.context.user, session_id)
The error come from Product.objects.get(id=product)
because product is an array Correction:错误来自
Product.objects.get(id=product)
因为 product 是一个数组更正:
products = [Product.objects.get(id=product) for product in products]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.