type-graphql类型Int和Number有什么区别? 我想使用纯整数作为我的graphql参数(例如1,而不是“ 1”或1.0)。
@GQL.Field(type => Number)
此外,我观察到的是当我将参数类型设置为“ Number”时,出现在graphql-playground中的模式将这些参数类型显示为float。
@GQL.Mutation(returns => Booking)
public async addBooking(
@GQL.Arg("user") user: number,
@GQL.Arg("bookingType") bookingType: number,
@GQL.Arg("start") start: Date,
@GQL.Arg("end") end: Date,
@GQL.Arg("bookingPackage", { nullable: true }) bookingPackage?: number,
@GQL.Arg("bookingAddons", type => [ Number, ], { nullable: true, }) bookingAddons?: number[],
@GQL.Arg("payment", { nullable: true }) payment?: number
) {
let booking = new Booking()
booking.user = user
booking.bookingType = bookingType
booking.start = start
booking.end = end
if (bookingPackage) booking.bookingPackage = bookingPackage
if (bookingAddons) booking.bookingAddons = bookingAddons
if (payment) booking.payment = payment
await booking.save()
return booking
}
出现在graphql-playground中的模式:
addBooking(
payment: Float
bookingAddons: [Float!]
bookingPackage: Float
end: DateTime!
start: DateTime!
bookingType: Float!
user: Float!
): Booking!
答案 0 :(得分:1)
https://19majkel94.github.io/type-graphql/docs/scalars.html#aliases
JavaScript编号将在架构中自动变为GraphQLFloat
那是因为JS中的number
被表示为双精度,所以Number = Float。
如果需要整数,请使用Int
。