Skip to content

Commit df660f9

Browse files
ardatanAlan-Cha
authored andcommitted
Use GraphQL Scalars
1 parent 5a13419 commit df660f9

File tree

6 files changed

+23
-15
lines changed

6 files changed

+23
-15
lines changed

packages/openapi-to-graphql/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@
8585
"debug": "^4.2.0",
8686
"deep-equal": "^2.0.5",
8787
"form-urlencoded": "^6.0.4",
88+
"graphql-scalars": "^1.10.0",
8889
"graphql-subscriptions": "^1.1.0",
89-
"graphql-type-json": "^0.3.2",
9090
"json-ptr": "^1.3.1",
9191
"jsonpath-plus": "^4.0.0",
9292
"oas-validator": "^5.0.2",

packages/openapi-to-graphql/src/oas_3_tools.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -471,12 +471,8 @@ export function getSchemaTargetGraphQLType<TSource, TContext, TArgs>(
471471

472472
// Special edge cases involving the schema format
473473
if (typeof schema.format === 'string') {
474-
/**
475-
* CASE: 64 bit int - return number instead of integer, leading to use of
476-
* GraphQLFloat, which can support 64 bits:
477-
*/
478474
if (schema.type === 'integer' && schema.format === 'int64') {
479-
return TargetGraphQLType.float
475+
return TargetGraphQLType.bigint
480476

481477
// CASE: id
482478
} else if (

packages/openapi-to-graphql/src/schema_builder.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import {
3838
} from 'graphql'
3939

4040
// Imports:
41-
import GraphQLJSON from 'graphql-type-json'
41+
import { GraphQLBigInt, GraphQLJSON } from 'graphql-scalars'
4242
import * as Oas3Tools from './oas_3_tools'
4343
import { getResolver, OPENAPI_TO_GRAPHQL } from './resolver_builder'
4444
import { createDataDef } from './preprocessor'
@@ -218,6 +218,10 @@ export function getGraphQLType<TSource, TContext, TArgs>({
218218
case TargetGraphQLType.json:
219219
def.graphQLType = CleanGraphQLJSON
220220
return def.graphQLType
221+
222+
case TargetGraphQLType.bigint:
223+
def.graphQLType = GraphQLBigInt
224+
return def.graphQLType
221225
}
222226
}
223227

packages/openapi-to-graphql/src/types/operation.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export enum TargetGraphQLType {
3737
float = 'float',
3838
boolean = 'boolean',
3939
id = 'id',
40+
bigint = 'bigint',
4041

4142
// JSON
4243
json = 'json',

packages/openapi-to-graphql/test/example_api.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ test('Ensure good naming for operations with duplicated schemas', () => {
635635
* CASE: 64 bit int - return number instead of integer, leading to use of
636636
* GraphQLFloat, which can support 64 bits:
637637
*/
638-
test('Get response containing 64-bit integer (using GraphQLFloat)', () => {
638+
test('Get response containing 64-bit integer (using GraphQLBigInt)', () => {
639639
const query = `{
640640
productReviews (id: "100") {
641641
timestamp
@@ -646,8 +646,8 @@ test('Get response containing 64-bit integer (using GraphQLFloat)', () => {
646646
expect(result).toEqual({
647647
data: {
648648
productReviews: [
649-
{ timestamp: 1502787600000000 },
650-
{ timestamp: 1502787400000000 }
649+
{ timestamp: BigInt('1502787600000000') },
650+
{ timestamp: BigInt('1502787400000000') }
651651
]
652652
}
653653
})

yarn.lock

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3028,6 +3028,13 @@ graphql-redis-subscriptions@^2.0.0:
30283028
optionalDependencies:
30293029
ioredis "^4.17.3"
30303030

3031+
graphql-scalars@^1.10.0:
3032+
version "1.10.0"
3033+
resolved "https://registry.yarnpkg.com/graphql-scalars/-/graphql-scalars-1.10.0.tgz#9daf9252b16e6fae553a06976163a23f41b65dfd"
3034+
integrity sha512-LONlj8FfhA2iGpkZJWf5e4PVAHXxnZEHSOEvowLYvNXl/TNnhIck8VmE+lren/aa6GKrG+lZufo5lgnyjxcF6g==
3035+
dependencies:
3036+
tslib "~2.2.0"
3037+
30313038
graphql-subscriptions@^0.4.2:
30323039
version "0.4.4"
30333040
resolved "https://registry.yarnpkg.com/graphql-subscriptions/-/graphql-subscriptions-0.4.4.tgz#39cff32d08dd3c990113864bab77154403727e9b"
@@ -3044,11 +3051,6 @@ graphql-subscriptions@^1.1.0:
30443051
dependencies:
30453052
iterall "^1.3.0"
30463053

3047-
graphql-type-json@^0.3.2:
3048-
version "0.3.2"
3049-
resolved "https://registry.yarnpkg.com/graphql-type-json/-/graphql-type-json-0.3.2.tgz#f53a851dbfe07bd1c8157d24150064baab41e115"
3050-
integrity sha512-J+vjof74oMlCWXSvt0DOf2APEdZOCdubEvGDUAlqH//VBYcOYsGgRW7Xzorr44LvkjiuvecWc8fChxuZZbChtg==
3051-
30523054
graphql@*, graphql@^15.3.0:
30533055
version "15.5.1"
30543056
resolved "https://registry.yarnpkg.com/graphql/-/graphql-15.5.1.tgz#f2f84415d8985e7b84731e7f3536f8bb9d383aad"
@@ -6629,6 +6631,11 @@ tslib@^2.0.0, tslib@^2.0.3, tslib@^2.3.0:
66296631
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.3.0.tgz#803b8cdab3e12ba581a4ca41c8839bbb0dacb09e"
66306632
integrity sha512-N82ooyxVNm6h1riLCoyS9e3fuJ3AMG2zIZs2Gd1ATcSFjSA23Q0fzjjZeh0jbJvWVDZ0cJT8yaNNaaXHzueNjg==
66316633

6634+
tslib@~2.2.0:
6635+
version "2.2.0"
6636+
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.2.0.tgz#fb2c475977e35e241311ede2693cee1ec6698f5c"
6637+
integrity sha512-gS9GVHRU+RGn5KQM2rllAlR3dU6m7AcpJKdtH8gFvQiC4Otgk98XnmMU+nZenHt/+VhnBPWwgrJsyrdcw6i23w==
6638+
66326639
tslint-config-standard@^9.0.0:
66336640
version "9.0.0"
66346641
resolved "https://registry.yarnpkg.com/tslint-config-standard/-/tslint-config-standard-9.0.0.tgz#349a94819d93d5f8d803e3c71cb58ef38eff88e0"

0 commit comments

Comments
 (0)