Floats are being converted to String
vinaybedre opened this issue · 4 comments
Floats in swagger spec are being converted to String in graphql.
Steps to reproduce:
npx swagger-to-graphql --swagger-schema=swagger_schema.yaml > ./types.graphql
swagger_schema.yaml
swagger: "2.0"
info:
version: 1.1.0
title: Test server
basePath: /api/v1
host: localhost
paths:
/user/{id}:
get:
operationId: getUserId
tags:
- users
produces:
- application/json
parameters:
- name: id
in: path
description: User Id
required: true
type: integer
format: int64
responses:
200:
description: A User Response
schema:
$ref: "#/definitions/UserResponse"
definitions:
UserResponse:
type: object
required:
- userId
properties:
userId:
type: integer
format: int64
userName:
type: string
Expected output:
type Query {
getUserId(id: Float!): UserResponse!
}
type UserResponse {
userId: Float!
userName: String
}
Actual output:
type Query {
getUserId(id: String!): UserResponse!
}
type UserResponse {
userId: String!
userName: String
}
Same here with int return type
"WorkflowCaseId": {
"format": "int64",
"type": "integer"
}
Gets back
type WorkflowCaseIdentifier {
WorkflowCaseId: String
}
Any remedy?
P.S. It's because of format https://github.com/yarax/swagger-to-graphql/blob/master/src/typeMap.ts#L52
@0xR Any reason to convert Int64 to String https://github.com/yarax/swagger-to-graphql/blob/master/src/typeMap.ts#L52?
The JavaScript number type doesn't have enough accuracy to represent a 64 bit integer. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER
It's safer to stick to a int32 on your backend. In Java an int would be 32 bit and a long would be 64 bit.
Thanks @0xR for the clarification 👍