1

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?

avocado
  • 79
  • 9

0 Answers0