GraphQL error: int() argument must be a string or a number, not 'list'
GraphQL error: int() argument must be a string or a number, not 'list'
我有这个突变:
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
}
}`
我想创建一个 productId 数组,但是当我改变时:我得到:
Mutation error: Error: GraphQL error: int() argument must be a string or a number, not 'list'
我的 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)
感谢帮助,有问题请教
我解决了,
如果您有同样的错误,并且您确定突变参数与声明的类型相同:问题来自您的突变函数:
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)
错误来自Product.objects.get(id=product)
因为产品是一个数组
更正:
products = [Product.objects.get(id=product) for product in products]
我有这个突变:
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
}
}`
我想创建一个 productId 数组,但是当我改变时:我得到:
Mutation error: Error: GraphQL error: int() argument must be a string or a number, not 'list'
我的 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)
感谢帮助,有问题请教
我解决了,
如果您有同样的错误,并且您确定突变参数与声明的类型相同:问题来自您的突变函数:
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)
错误来自Product.objects.get(id=product)
因为产品是一个数组
更正:
products = [Product.objects.get(id=product) for product in products]