Skip to content

Commit e4b8021

Browse files
authored
Don't cast integers to floats in Neptune schema (#62)
Test case for cast in `Case04.02` - update docs/samples/test cases closes #55
1 parent 9a3de7f commit e4b8021

27 files changed

+329
-123
lines changed

doc/routesExample.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ The utility then use this data to inference the GraphQL schema.
5252
"label": "airport",
5353
"properties": [
5454
{ "name": "country", "type": "String" },
55-
{ "name": "longest", "type": "Float" },
55+
{ "name": "longest", "type": "Int" },
5656
{ "name": "code", "type": "String" },
5757
{ "name": "city", "type": "String" },
58-
{ "name": "elev", "type": "Float" },
58+
{ "name": "elev", "type": "Int" },
5959
{ "name": "icao", "type": "String" },
6060
{ "name": "lon", "type": "Float" },
61-
{ "name": "runways", "type": "Float" },
61+
{ "name": "runways", "type": "Int" },
6262
{ "name": "region", "type": "String" },
6363
{ "name": "type", "type": "String" },
6464
{ "name": "lat", "type": "Float" },
@@ -153,13 +153,13 @@ input VersionInput {
153153
type Airport @alias(property: "airport") {
154154
_id: ID! @id
155155
country: String
156-
longest: Float
156+
longest: Int
157157
code: String
158158
city: String
159-
elev: Float
159+
elev: Int
160160
icao: String
161161
lon: Float
162-
runways: Float
162+
runways: Int
163163
region: String
164164
type: String
165165
lat: Float
@@ -175,13 +175,13 @@ type Airport @alias(property: "airport") {
175175
input AirportInput {
176176
_id: ID @id
177177
country: String
178-
longest: Float
178+
longest: Int
179179
code: String
180180
city: String
181-
elev: Float
181+
elev: Int
182182
icao: String
183183
lon: Float
184-
runways: Float
184+
runways: Int
185185
region: String
186186
type: String
187187
lat: Float

samples/airports.graphdb.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@
3030
"label": "airport",
3131
"properties": [
3232
{ "name": "country", "type": "String" },
33-
{ "name": "longest", "type": "Float" },
33+
{ "name": "longest", "type": "Int" },
3434
{ "name": "code", "type": "String" },
3535
{ "name": "city", "type": "String" },
36-
{ "name": "elev", "type": "Float" },
36+
{ "name": "elev", "type": "Int" },
3737
{ "name": "icao", "type": "String" },
3838
{ "name": "lon", "type": "Float" },
39-
{ "name": "runways", "type": "Float" },
39+
{ "name": "runways", "type": "Int" },
4040
{ "name": "region", "type": "String" },
4141
{ "name": "type", "type": "String" },
4242
{ "name": "lat", "type": "Float" },

samples/airports.source.schema.graphql

+6-6
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ input VersionInput {
5151
type Airport @alias(property: "airport") {
5252
_id: ID! @id
5353
country: String
54-
longest: Float
54+
longest: Int
5555
code: String
5656
city: String
57-
elev: Float
57+
elev: Int
5858
icao: String
5959
lon: Float
60-
runways: Float
60+
runways: Int
6161
region: String
6262
type: String
6363
lat: Float
@@ -74,13 +74,13 @@ type Airport @alias(property: "airport") {
7474
input AirportInput {
7575
_id: ID @id
7676
country: String
77-
longest: Float
77+
longest: Int
7878
code: String
7979
city: String
80-
elev: Float
80+
elev: Int
8181
icao: String
8282
lon: Float
83-
runways: Float
83+
runways: Int
8484
region: String
8585
type: String
8686
lat: Float

src/NeptuneSchema.js

+10-9
Original file line numberDiff line numberDiff line change
@@ -197,18 +197,19 @@ async function getEdgesDirections() {
197197

198198

199199
function CastGraphQLType(value) {
200-
let propertyType = 'String';
201-
202200
if (typeof value === 'number') {
203-
if (Number.isInteger(value)) {
204-
propertyType = 'Int';
205-
}
206-
propertyType = 'Float';
201+
return Number.isInteger(value) ? 'Int' : 'Float';
202+
}
203+
204+
if (typeof value === 'boolean') {
205+
return 'Boolean';
206+
}
207+
208+
if (value instanceof Date) {
209+
return 'Date';
207210
}
208211

209-
if (typeof value === 'boolean') propertyType = 'Boolean';
210-
if (value instanceof Date) propertyType = 'Date';
211-
return propertyType;
212+
return 'String';
212213
}
213214

214215

src/test/airports-neptune-schema.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,11 @@
8888
},
8989
{
9090
"name": "longest",
91-
"type": "Float"
91+
"type": "Int"
9292
},
9393
{
9494
"name": "runways",
95-
"type": "Float"
95+
"type": "Int"
9696
},
9797
{
9898
"name": "desc",
@@ -108,7 +108,7 @@
108108
},
109109
{
110110
"name": "elev",
111-
"type": "Float"
111+
"type": "Int"
112112
}
113113
]
114114
}
@@ -135,7 +135,7 @@
135135
"properties": [
136136
{
137137
"name": "dist",
138-
"type": "Float"
138+
"type": "Int"
139139
}
140140
],
141141
"directions": [

src/test/airports.graphql

+8-8
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ icao: String
5656
code: String
5757
country: String
5858
lat: Float
59-
longest: Float
60-
runways: Float
59+
longest: Int
60+
runways: Int
6161
desc: String
6262
lon: Float
6363
region: String
64-
elev: Float
64+
elev: Int
6565
continentContainsIn: Continent @relationship(edgeType:"contains", direction:IN)
6666
countryContainsIn: Country @relationship(edgeType:"contains", direction:IN)
6767
airportRoutesOut(filter: AirportInput, options: Options): [Airport] @relationship(edgeType:"route", direction:OUT)
@@ -78,12 +78,12 @@ icao: String
7878
code: String
7979
country: String
8080
lat: Float
81-
longest: Float
82-
runways: Float
81+
longest: Int
82+
runways: Int
8383
desc: String
8484
lon: Float
8585
region: String
86-
elev: Float
86+
elev: Int
8787
}
8888

8989
type Contains @alias(property:"contains") {
@@ -92,11 +92,11 @@ _id: ID! @id
9292

9393
type Route @alias(property:"route") {
9494
_id: ID! @id
95-
dist: Float
95+
dist: Int
9696
}
9797

9898
input RouteInput {
99-
dist: Float
99+
dist: Int
100100
}
101101

102102
input Options {

src/test/dining-neptune-schema.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
},
2323
{
2424
"name": "rating",
25-
"type": "Float"
25+
"type": "Int"
2626
}
2727
]
2828
},
@@ -39,7 +39,7 @@
3939
},
4040
{
4141
"name": "person_id",
42-
"type": "Float"
42+
"type": "Int"
4343
}
4444
]
4545
},
@@ -48,7 +48,7 @@
4848
"properties": [
4949
{
5050
"name": "restaurant_id",
51-
"type": "Float"
51+
"type": "Int"
5252
},
5353
{
5454
"name": "name",

src/test/dining.graphql

+6-6
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type Review @alias(property:"review") {
1616
_id: ID! @id
1717
body: String
1818
created_date: String
19-
rating: Float
19+
rating: Int
2020
personWroteIn: Person @relationship(edgeType:"wrote", direction:IN)
2121
restaurantAboutOut: Restaurant @relationship(edgeType:"about", direction:OUT)
2222
wrote:Wrote
@@ -27,14 +27,14 @@ input ReviewInput {
2727
_id: ID @id
2828
body: String
2929
created_date: String
30-
rating: Float
30+
rating: Int
3131
}
3232

3333
type Person @alias(property:"person") {
3434
_id: ID! @id
3535
first_name: String
3636
last_name: String
37-
person_id: Float
37+
person_id: Int
3838
cityLivesOut: City @relationship(edgeType:"lives", direction:OUT)
3939
reviewWrotesOut(filter: ReviewInput, options: Options): [Review] @relationship(edgeType:"wrote", direction:OUT)
4040
personFriendssOut(filter: PersonInput, options: Options): [Person] @relationship(edgeType:"friends", direction:OUT)
@@ -48,12 +48,12 @@ input PersonInput {
4848
_id: ID @id
4949
first_name: String
5050
last_name: String
51-
person_id: Float
51+
person_id: Int
5252
}
5353

5454
type Restaurant @alias(property:"restaurant") {
5555
_id: ID! @id
56-
restaurant_id: Float
56+
restaurant_id: Int
5757
name: String
5858
address: String
5959
cityWithinOut: City @relationship(edgeType:"within", direction:OUT)
@@ -66,7 +66,7 @@ about:About
6666

6767
input RestaurantInput {
6868
_id: ID @id
69-
restaurant_id: Float
69+
restaurant_id: Int
7070
name: String
7171
address: String
7272
}

src/test/epl-neptune-schema.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
"properties": [
66
{
77
"name": "opened",
8-
"type": "Float"
8+
"type": "Int"
99
},
1010
{
1111
"name": "capacity",
12-
"type": "Float"
12+
"type": "Int"
1313
},
1414
{
1515
"name": "name",
@@ -47,7 +47,7 @@
4747
},
4848
{
4949
"name": "founded",
50-
"type": "Float"
50+
"type": "Int"
5151
}
5252
]
5353
},

src/test/epl.graphql

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
type Stadium {
22
_id: ID! @id
3-
opened: Float
4-
capacity: Float
3+
opened: Int
4+
capacity: Int
55
name: String
66
cityCity_edgeOut: City @relationship(edgeType:"CITY_EDGE", direction:OUT)
77
CITY_EDGE:City_edge
@@ -10,8 +10,8 @@ STADIUM_EDGE:Stadium_edge
1010

1111
input StadiumInput {
1212
_id: ID @id
13-
opened: Float
14-
capacity: Float
13+
opened: Int
14+
capacity: Int
1515
name: String
1616
}
1717

@@ -34,7 +34,7 @@ _id: ID! @id
3434
nickname: String
3535
name: String
3636
fullName: String
37-
founded: Float
37+
founded: Int
3838
leagueCurrent_leagueOut: League @relationship(edgeType:"CURRENT_LEAGUE", direction:OUT)
3939
CURRENT_LEAGUE:Current_league
4040
STADIUM_EDGE:Stadium_edge
@@ -45,7 +45,7 @@ _id: ID @id
4545
nickname: String
4646
name: String
4747
fullName: String
48-
founded: Float
48+
founded: Int
4949
}
5050

5151
type City {

src/test/fraud-neptune-schema.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"properties": [
4141
{
4242
"name": "amount",
43-
"type": "Float"
43+
"type": "Int"
4444
},
4545
{
4646
"name": "created",

src/test/fraud.graphql

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ name: String
4646

4747
type Transaction {
4848
_id: ID! @id
49-
amount: Float
49+
amount: Int
5050
created: String
5151
accountAccount_edgeOut: Account @relationship(edgeType:"ACCOUNT_EDGE", direction:OUT)
5252
ipaddressFeature_of_transactionIn: Ipaddress @relationship(edgeType:"FEATURE_OF_TRANSACTION", direction:IN)
@@ -59,7 +59,7 @@ MERCHANT_EDGE:Merchant_edge
5959

6060
input TransactionInput {
6161
_id: ID @id
62-
amount: Float
62+
amount: Int
6363
created: String
6464
}
6565

test/TestCases/Case01/outputReference/output.neptune.schema.json

Whitespace-only changes.

0 commit comments

Comments
 (0)