简体   繁体   中英

How to use type Number or Array in GraphQL typedefs

I'm trying to use type Number and type Array in my typedefs for a Product type in GraphQL. But GraphQL gives me some errors in the console. It's my first time using GraphQL though.

Unknown type "Array".

Unknown type "Number".

Here's the typedef I'm trying to create.

 type Product {
    sku: String
    productName: String
    isNewProduct: Boolean
    isPromo: Boolean
    promoType: String
    promoPrice: Number
    promoStart: String
    promoEnd: String
    stockingPrice: Number
    finalPrice: Number
    isActiveProduct: Boolean
    availableQuantity: Number
    quantityUnit: String
    category: String
    saleType: String
    manufactureCompany: String
    year: String
    color: String
    tags: Array
    variantID: String
    description: String
  }

I checked around and saw that there are type ID and type Float in the case for numbers.

But, I'm writing JavaScript. There's a possibility that the promoPrice property will be getting either a float or an int and I don't want an error thrown if that's the case. That's why I want to use type Number.

Also, what do I do in the case for arrays containing both strings and numbers?

The GraphQL schema language supports the scalar types of String, Int, Float, Boolean, and ID. Use Int if you want to use Number. If your tags are Array of Strings then You could actually define like tags: [String]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM