简体   繁体   English

GraphQL 错误:int() 参数必须是字符串或数字,而不是“列表”

[英]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.

相关问题 为什么int()参数必须是字符串或数字,而不是'list'? - Why int() argument must be a string or a number, not 'list'? TypeError:int()参数必须是字符串或数字,而不是“列表” - TypeError: int() argument must be a string or a number, not 'list' int() 参数必须是字符串或数字 - int() argument must be a string or a number Django 2.2 错误:int() 参数必须是字符串、类似字节的 object 或数字,而不是“列表” - Django 2.2 error: int() argument must be a string, a bytes-like object or a number, not 'list' int()参数必须是字符串,类似字节的对象或数字,而不是'list'代码错误 - int() argument must be a string, a bytes-like object or a number, not 'list' Error in code 错误:装饰器@action中的“int()参数必须是一个字符串,一个类似字节的object或一个数字,而不是'list'” - error: “int() argument must be a string, a bytes-like object or a number, not 'list'” in decorator @action int()参数必须是字符串,类似字节的对象或数字,而不是“列表” - int() argument must be a string, a bytes-like object or a number, not 'list' Int Argument必须是字符串或数字,而不是列表,Python csv - Int Argument Must be a String or a Number, Not a List, Python csv Django错误:TypeError:int()参数必须是字符串或数字,而不是“ BuildsTable” - Django Error: TypeError: int() argument must be a string or a number, not 'BuildsTable' int() 参数必须是字符串或数字,而不是“NoneType” - int() argument must a string or a number, not 'NoneType'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM