[英]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.我正在尝试在我的 typedef 中为 GraphQL 中的 Product 类型使用类型 Number 和类型 Array 。 But GraphQL gives me some errors in the console.但是 GraphQL 在控制台中给了我一些错误。 It's my first time using GraphQL though.不过,这是我第一次使用 GraphQL。
Unknown type "Array".
Unknown type "Number".
Here's the typedef I'm trying to create.这是我正在尝试创建的 typedef。
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.我检查了一下,发现在数字的情况下有类型 ID 和类型 Float。
But, I'm writing JavaScript.但是,我正在编写 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. promoPrice 属性可能会得到一个浮点数或一个整数,如果是这种情况,我不希望抛出错误。 That's why I want to use type Number.这就是为什么我想使用类型 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. GraphQL 模式语言支持 String、Int、Float、Boolean 和 ID 的标量类型。 Use Int if you want to use Number.如果您想使用 Number,请使用 Int。 If your tags are Array of Strings then You could actually define like tags: [String]
如果您的标签是字符串数组,那么您实际上可以定义类似的tags: [String]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.