7
7
8
8
/* globals beforeAll, test, expect */
9
9
10
- const openapiToGraphql = require ( '../lib/index.js' )
10
+ import * as openapiToGraphql from '../lib/index.js'
11
11
const { graphql, parse, validate } = require ( 'graphql' )
12
12
const { startServer, stopServer } = require ( './example_api_server' )
13
13
14
- let createdSchema
15
- let oas = require ( './fixtures/example_oas.json' )
14
+ const oas = require ( './fixtures/example_oas.json' )
16
15
const PORT = 3002
17
16
// update PORT for this test case:
18
17
oas . servers [ 0 ] . variables . port . default = String ( PORT )
19
18
19
+ let createdSchema
20
+
20
21
/**
21
22
* Set up the schema first and run example API server
22
23
*/
@@ -841,12 +842,12 @@ test('Capitalized enum values can be returned', () => {
841
842
} )
842
843
843
844
test ( 'Define header and query options' , ( ) => {
844
- let options = {
845
+ const options = {
845
846
headers : {
846
847
exampleHeader : 'some-value'
847
848
} ,
848
849
qs : {
849
- limit : 30
850
+ limit : '30'
850
851
}
851
852
}
852
853
const query = `{
@@ -856,8 +857,8 @@ test('Define header and query options', () => {
856
857
. createGraphQlSchema ( oas , options )
857
858
. then ( ( { schema } ) => {
858
859
// validate that 'limit' parameter is covered by options:
859
- let ast = parse ( query )
860
- let errors = validate ( schema , ast )
860
+ const ast = parse ( query )
861
+ const errors = validate ( schema , ast )
861
862
expect ( errors ) . toEqual ( [ ] )
862
863
return graphql ( schema , query ) . then ( result => {
863
864
expect ( result ) . toEqual ( {
@@ -922,7 +923,7 @@ test('Error contains extension', () => {
922
923
} )
923
924
924
925
test ( 'Option provideErrorExtensions should prevent error extensions from being created' , ( ) => {
925
- let options = {
926
+ const options = {
926
927
provideErrorExtensions : false
927
928
}
928
929
const query = `query {
@@ -933,8 +934,8 @@ test('Option provideErrorExtensions should prevent error extensions from being c
933
934
return openapiToGraphql
934
935
. createGraphQlSchema ( oas , options )
935
936
. then ( ( { schema } ) => {
936
- let ast = parse ( query )
937
- let errors = validate ( schema , ast )
937
+ const ast = parse ( query )
938
+ const errors = validate ( schema , ast )
938
939
expect ( errors ) . toEqual ( [ ] )
939
940
return graphql ( schema , query ) . then ( result => {
940
941
expect ( result ) . toEqual ( {
@@ -959,7 +960,7 @@ test('Option provideErrorExtensions should prevent error extensions from being c
959
960
} )
960
961
961
962
test ( 'Option customResolver' , ( ) => {
962
- let options = {
963
+ const options = {
963
964
customResolvers : {
964
965
'Example API' : {
965
966
'/users/{username}' : {
@@ -980,8 +981,8 @@ test('Option customResolver', () => {
980
981
return openapiToGraphql
981
982
. createGraphQlSchema ( oas , options )
982
983
. then ( ( { schema } ) => {
983
- let ast = parse ( query )
984
- let errors = validate ( schema , ast )
984
+ const ast = parse ( query )
985
+ const errors = validate ( schema , ast )
985
986
expect ( errors ) . toEqual ( [ ] )
986
987
return graphql ( schema , query ) . then ( result => {
987
988
expect ( result ) . toEqual ( {
@@ -996,7 +997,7 @@ test('Option customResolver', () => {
996
997
} )
997
998
998
999
test ( 'Option customResolver with links' , ( ) => {
999
- let options = {
1000
+ const options = {
1000
1001
customResolvers : {
1001
1002
'Example API' : {
1002
1003
'/users/{username}' : {
@@ -1026,8 +1027,8 @@ test('Option customResolver with links', () => {
1026
1027
return openapiToGraphql
1027
1028
. createGraphQlSchema ( oas , options )
1028
1029
. then ( ( { schema } ) => {
1029
- let ast = parse ( query )
1030
- let errors = validate ( schema , ast )
1030
+ const ast = parse ( query )
1031
+ const errors = validate ( schema , ast )
1031
1032
expect ( errors ) . toEqual ( [ ] )
1032
1033
return graphql ( schema , query ) . then ( result => {
1033
1034
expect ( result ) . toEqual ( {
@@ -1050,7 +1051,7 @@ test('Option customResolver with links', () => {
1050
1051
} )
1051
1052
1052
1053
test ( 'Option customResolver using resolver arguments' , ( ) => {
1053
- let options = {
1054
+ const options = {
1054
1055
customResolvers : {
1055
1056
'Example API' : {
1056
1057
'/users/{username}' : {
@@ -1071,8 +1072,8 @@ test('Option customResolver using resolver arguments', () => {
1071
1072
return openapiToGraphql
1072
1073
. createGraphQlSchema ( oas , options )
1073
1074
. then ( ( { schema } ) => {
1074
- let ast = parse ( query )
1075
- let errors = validate ( schema , ast )
1075
+ const ast = parse ( query )
1076
+ const errors = validate ( schema , ast )
1076
1077
expect ( errors ) . toEqual ( [ ] )
1077
1078
return graphql ( schema , query ) . then ( result => {
1078
1079
expect ( result ) . toEqual ( {
@@ -1087,7 +1088,7 @@ test('Option customResolver using resolver arguments', () => {
1087
1088
} )
1088
1089
1089
1090
test ( 'Option customResolver using resolver arguments that are sanitized' , ( ) => {
1090
- let options = {
1091
+ const options = {
1091
1092
customResolvers : {
1092
1093
'Example API' : {
1093
1094
'/products/{product-id}' : {
@@ -1110,8 +1111,8 @@ test('Option customResolver using resolver arguments that are sanitized', () =>
1110
1111
return openapiToGraphql
1111
1112
. createGraphQlSchema ( oas , options )
1112
1113
. then ( ( { schema } ) => {
1113
- let ast = parse ( query )
1114
- let errors = validate ( schema , ast )
1114
+ const ast = parse ( query )
1115
+ const errors = validate ( schema , ast )
1115
1116
expect ( errors ) . toEqual ( [ ] )
1116
1117
return graphql ( schema , query ) . then ( result => {
1117
1118
expect ( result ) . toEqual ( {
@@ -1126,7 +1127,7 @@ test('Option customResolver using resolver arguments that are sanitized', () =>
1126
1127
} )
1127
1128
1128
1129
test ( 'Option addLimitArgument' , ( ) => {
1129
- let options = {
1130
+ const options = {
1130
1131
addLimitArgument : true
1131
1132
}
1132
1133
const query = `query {
@@ -1146,8 +1147,8 @@ test('Option addLimitArgument', () => {
1146
1147
return openapiToGraphql
1147
1148
. createGraphQlSchema ( oas , options )
1148
1149
. then ( ( { schema } ) => {
1149
- let ast = parse ( query )
1150
- let errors = validate ( schema , ast )
1150
+ const ast = parse ( query )
1151
+ const errors = validate ( schema , ast )
1151
1152
expect ( errors ) . toEqual ( [ ] )
1152
1153
return graphql ( schema , query ) . then ( result => {
1153
1154
expect ( result ) . toEqual ( {
@@ -1288,7 +1289,7 @@ test('Stringify objects without defined properties', () => {
1288
1289
} )
1289
1290
1290
1291
test ( 'Generate "Equivalent to..." messages' , ( ) => {
1291
- let options = {
1292
+ const options = {
1292
1293
// Used to simplify test. Otherwise viewers will polute query/mutation fields.
1293
1294
viewer : false
1294
1295
}
@@ -1318,8 +1319,8 @@ test('Generate "Equivalent to..." messages', () => {
1318
1319
const promise = openapiToGraphql
1319
1320
. createGraphQlSchema ( oas , options )
1320
1321
. then ( ( { schema } ) => {
1321
- let ast = parse ( query )
1322
- let errors = validate ( schema , ast )
1322
+ const ast = parse ( query )
1323
+ const errors = validate ( schema , ast )
1323
1324
expect ( errors ) . toEqual ( [ ] )
1324
1325
return graphql ( schema , query ) . then ( result => {
1325
1326
// Make sure all query fields have the message
@@ -1381,7 +1382,7 @@ test('Generate "Equivalent to..." messages', () => {
1381
1382
} )
1382
1383
1383
1384
test ( 'Withhold "Equivalent to..." messages' , ( ) => {
1384
- let options = {
1385
+ const options = {
1385
1386
// Used to simplify test. Otherwise viewers will polute query/mutation fields.
1386
1387
viewer : false ,
1387
1388
equivalentToMessages : false
@@ -1412,8 +1413,8 @@ test('Withhold "Equivalent to..." messages', () => {
1412
1413
const promise = openapiToGraphql
1413
1414
. createGraphQlSchema ( oas , options )
1414
1415
. then ( ( { schema } ) => {
1415
- let ast = parse ( query )
1416
- let errors = validate ( schema , ast )
1416
+ const ast = parse ( query )
1417
+ const errors = validate ( schema , ast )
1417
1418
expect ( errors ) . toEqual ( [ ] )
1418
1419
return graphql ( schema , query ) . then ( result => {
1419
1420
expect (
@@ -1445,8 +1446,8 @@ test('Withhold "Equivalent to..." messages', () => {
1445
1446
const promise2 = openapiToGraphql
1446
1447
. createGraphQlSchema ( oas , options )
1447
1448
. then ( ( { schema } ) => {
1448
- let ast = parse ( query )
1449
- let errors = validate ( schema , ast )
1449
+ const ast = parse ( query )
1450
+ const errors = validate ( schema , ast )
1450
1451
expect ( errors ) . toEqual ( [ ] )
1451
1452
return graphql ( schema , query2 ) . then ( result => {
1452
1453
expect (
0 commit comments