将INT参数传递给突变继电器和打字稿
我使用的架构第一种方法具有以下输入类型,用于
input VerifyBankAccountInput {
bankAccountId: ID!
amount1Cents: Int!
amount2Cents: Int!
}
在我使用的tyspript中继电器上的前端突变。在生成的graphql.ts
文件中,int
类型被映射到号码
。在将其传递给突变之前,我确保这两个金额为number
(而不是String
)。但是,在GraphQl的帖子查询中,我注意到这些值成为float
和我的服务器错误。它在DEV和PROD之间或两个值之间并不是真正的一致性(如下所示)(都使用完全相同的代码)。
输入:{bankAccountid:“ somerelayid”,金额1cents:56.9999999999999999,量,金额2cents:61}
如何确保如何确保number
作为int
而不是突变中的float
?
我尝试在此处遵循建议 https:/https:/ /spin.atomicobject.com/2018/11/05/usish-an-in-int-type-in-typescript/ ,但由于graphql.ts
中生成的代码而被卡住了号码
。获取错误:键入'bigint'不能分配给'number'。
我可以去更改生成的graphql.ts
中的类型,但是每次都会被覆盖我使用“ realay-compiler -src ./src -schema./schema.graphql -language tyspercript -customscalars.url = url = url -customscalars.localdate = localdate -customScalararrarys.customscalarars.s.instant = string = string string”
。
我也可以简单地围绕编号
确保没有小数点位置,但对我来说似乎有些脆弱。
使用模式的第一种方法处理此操作的正确方法是什么?
I am using a schema first approach have the following Input type for a mutation
input VerifyBankAccountInput {
bankAccountId: ID!
amount1Cents: Int!
amount2Cents: Int!
}
On the frontend I am using relay with typescript. In the generated graphql.ts
file the Int
type gets mapped to number
. I make sure these two amounts are number
(and not string
) before I pass it to the mutation. However, in the POST query from graphql I notice that these values become Float
and my server errors because of that. It's not really consistent across dev and prod or across the two values either as shown below (both use exact same code).
input:{bankAccountId: "SomeRelayId", amount1Cents: 56.99999999999999, amount2Cents: 61}
How do I make sure that the number
is sent as an Int
and not a Float
in a mutation?
I tried following the suggestions here https://spin.atomicobject.com/2018/11/05/using-an-int-type-in-typescript/ but got stuck because the generated code in graphql.ts
still expects a number
. Getting error: Type 'BigInt' is not assignable to type 'number'.
I could go and change the type in the generated graphql.ts
but that would be overwritten every time I recompile using "relay-compiler --src ./src --schema ./schema.graphql --language typescript --customScalars.URL=URL --customScalars.LocalDate=LocalDate --customScalars.Instant=string"
.
I could also simply round the number
to make sure there are no decimal places but that seems a bit brittle to me.
What is the right way to handle this with the schema first approach?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论