File tree 10 files changed +54
-27
lines changed
fieldExtensions/__tests__/fixtures
simple/__tests__/fixtures 10 files changed +54
-27
lines changed Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ workflows:
12
12
# definitions for field extensions in older @types/graphql versions
13
13
matrix :
14
14
parameters :
15
- graphql-version : ['~14.6', '~14.7', '~15.0']
15
+ graphql-version : ['~14.6', '~14.7', '~15.0', '~16.0' ]
16
16
- test-and-build :
17
17
# Leave graphql-version unspecified to respect the lockfile and also run tsc
18
18
name : test-and-build-with-typecheck
Original file line number Diff line number Diff line change 16
16
"build:test:esm" : " tsc -p ./tsconfig.test.esm.json && ./fix-hybrid-module.test.esm.sh" ,
17
17
"test" : " npm run lint && npm run build:test:cjs && npm run testonly:cjs && npm run build:test:esm && npm run testonly:esm" ,
18
18
"testonly:cjs" : " mocha --check-leaks --exit --full-trace 'dist/test/cjs/**/__tests__/**/*-test.js'" ,
19
- "testonly:esm" : " mocha --check-leaks --exit --full-trace 'dist/test/esm/**/__tests__/**/*-test.js'" ,
19
+ "testonly:esm" : " mocha -n experimental-json-modules - -check-leaks --exit --full-trace 'dist/test/esm/**/__tests__/**/*-test.js'" ,
20
20
"dist" : " npm run clean && npm run build" ,
21
21
"prepare" : " npm run clean && npm run dist"
22
22
},
27
27
"lodash.get" : " ^4.4.2"
28
28
},
29
29
"peerDependencies" : {
30
- "graphql" : " ^14.6.0 || ^15.0.0"
30
+ "graphql" : " ^14.6.0 || ^15.0.0 || ^16.0.0 "
31
31
},
32
32
"files" : [
33
33
" dist" ,
56
56
"@types/chai" : " ^4.2.22" ,
57
57
"@types/lodash.get" : " ^4.4.6" ,
58
58
"@types/mocha" : " ^9.0.0" ,
59
+ "@types/semver" : " ^7.3.9" ,
59
60
"@typescript-eslint/eslint-plugin" : " ^5.1.0" ,
60
61
"@typescript-eslint/parser" : " ^5.1.0" ,
61
62
"chai" : " ^4.3.4" ,
62
63
"eslint" : " ^8.0.1" ,
63
- "graphql" : " 14.6.0" ,
64
+ "graphql" : " ~ 14.6.0 || ~15.0.0 || ~16.0 .0" ,
64
65
"mocha" : " ^9.1.3" ,
65
66
"prettier" : " ^2.4.1" ,
66
67
"rimraf" : " ^3.0.2" ,
68
+ "semver" : " ^7.3.5" ,
67
69
"typescript" : " ^4.4.4"
68
70
}
69
71
}
Original file line number Diff line number Diff line change @@ -201,7 +201,7 @@ export default class QueryComplexity {
201
201
202
202
onOperationDefinitionLeave (
203
203
operation : OperationDefinitionNode
204
- ) : GraphQLError | undefined {
204
+ ) : GraphQLError | void {
205
205
if (
206
206
typeof this . options . operationName === 'string' &&
207
207
this . options . operationName !== operation . name . value
@@ -268,7 +268,9 @@ export default class QueryComplexity {
268
268
childNode ,
269
269
this . variableValues || { }
270
270
) ;
271
- includeNode = values . if ;
271
+ if ( typeof values . if === 'boolean' ) {
272
+ includeNode = values . if ;
273
+ }
272
274
break ;
273
275
}
274
276
case 'skip' : {
@@ -277,7 +279,9 @@ export default class QueryComplexity {
277
279
childNode ,
278
280
this . variableValues || { }
279
281
) ;
280
- skipNode = values . if ;
282
+ if ( typeof values . if === 'boolean' ) {
283
+ skipNode = values . if ;
284
+ }
281
285
break ;
282
286
}
283
287
}
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ import {
15
15
} from 'graphql' ;
16
16
17
17
import { ComplexityEstimatorArgs } from '../../QueryComplexity.js' ;
18
+ import { compatResolveType } from '../utils/compatResolveType.js' ;
18
19
19
20
const Item : GraphQLObjectType = new GraphQLObjectType ( {
20
21
name : 'Item' ,
@@ -62,7 +63,7 @@ const NameInterface = new GraphQLInterfaceType({
62
63
fields : {
63
64
name : { type : GraphQLString } ,
64
65
} ,
65
- resolveType : ( ) => Item ,
66
+ resolveType : compatResolveType ( Item ) ,
66
67
} ) ;
67
68
68
69
const SecondItem = new GraphQLObjectType ( {
@@ -86,15 +87,15 @@ const EnumType = new GraphQLEnumType({
86
87
const Union = new GraphQLUnionType ( {
87
88
name : 'Union' ,
88
89
types : [ Item , SecondItem ] ,
89
- resolveType : ( ) => Item ,
90
+ resolveType : compatResolveType ( Item ) ,
90
91
} ) ;
91
92
92
93
const UnionInterface = new GraphQLInterfaceType ( {
93
94
name : 'UnionInterface' ,
94
95
fields : ( ) => ( {
95
96
union : { type : Union } ,
96
97
} ) ,
97
- resolveType : ( ) => Item ,
98
+ resolveType : compatResolveType ( Item ) ,
98
99
} ) ;
99
100
100
101
const SDLInterface = new GraphQLInterfaceType ( {
Original file line number Diff line number Diff line change
1
+ import { GraphQLType } from 'graphql' ;
2
+
3
+ import graphqlPackage from 'graphql/package.json' ;
4
+ import semver from 'semver' ;
5
+
6
+ /**
7
+ * GraphQL v16 changed how types are resolved, so we need to return a string
8
+ * for the type name for newer version, and the type itself to be compatible with older versions.
9
+ *
10
+ * @param type
11
+ * @returns
12
+ */
13
+ export function compatResolveType ( type : GraphQLType ) : any {
14
+ if ( semver . gte ( graphqlPackage . version , '16.0.0' ) ) {
15
+ return ( ) => type . toString ( ) ;
16
+ } else {
17
+ return ( ) => type ;
18
+ }
19
+ }
Original file line number Diff line number Diff line change @@ -61,7 +61,7 @@ export default function (
61
61
62
62
// Get multipliers
63
63
let totalMultiplier = 1 ;
64
- if ( values . multipliers ) {
64
+ if ( values . multipliers && Array . isArray ( values . multipliers ) ) {
65
65
totalMultiplier = values . multipliers . reduce (
66
66
( aggregated : number , multiplier : string ) => {
67
67
const multiplierValue = get ( args . args , multiplier ) ;
@@ -78,6 +78,6 @@ export default function (
78
78
) ;
79
79
}
80
80
81
- return ( values . value + args . childComplexity ) * totalMultiplier ;
81
+ return ( Number ( values . value ) + args . childComplexity ) * totalMultiplier ;
82
82
} ;
83
83
}
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ import {
14
14
GraphQLUnionType ,
15
15
GraphQLInterfaceType ,
16
16
} from 'graphql' ;
17
+ import { compatResolveType } from '../../../../__tests__/utils/compatResolveType.js' ;
17
18
18
19
import { ComplexityEstimatorArgs } from '../../../../QueryComplexity.js' ;
19
20
@@ -68,7 +69,7 @@ const NameInterface = new GraphQLInterfaceType({
68
69
fields : {
69
70
name : { type : GraphQLString } ,
70
71
} ,
71
- resolveType : ( ) => Item ,
72
+ resolveType : compatResolveType ( Item ) ,
72
73
} ) ;
73
74
74
75
const SecondItem = new GraphQLObjectType ( {
@@ -92,7 +93,7 @@ const EnumType = new GraphQLEnumType({
92
93
const Union = new GraphQLUnionType ( {
93
94
name : 'Union' ,
94
95
types : [ Item , SecondItem ] ,
95
- resolveType : ( ) => Item ,
96
+ resolveType : compatResolveType ( Item ) ,
96
97
} ) ;
97
98
98
99
const Query = new GraphQLObjectType ( {
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ import {
13
13
GraphQLUnionType ,
14
14
GraphQLInterfaceType ,
15
15
} from 'graphql' ;
16
+ import { compatResolveType } from '../../../../__tests__/utils/compatResolveType.js' ;
16
17
17
18
const Item : GraphQLObjectType = new GraphQLObjectType ( {
18
19
name : 'Item' ,
@@ -43,7 +44,7 @@ const NameInterface = new GraphQLInterfaceType({
43
44
fields : {
44
45
name : { type : GraphQLString } ,
45
46
} ,
46
- resolveType : ( ) => Item ,
47
+ resolveType : compatResolveType ( Item ) ,
47
48
} ) ;
48
49
49
50
const SecondItem = new GraphQLObjectType ( {
@@ -67,7 +68,7 @@ const EnumType = new GraphQLEnumType({
67
68
const Union = new GraphQLUnionType ( {
68
69
name : 'Union' ,
69
70
types : [ Item , SecondItem ] ,
70
- resolveType : ( ) => Item ,
71
+ resolveType : compatResolveType ( Item ) ,
71
72
} ) ;
72
73
73
74
const Query = new GraphQLObjectType ( {
Original file line number Diff line number Diff line change 2
2
"compilerOptions" : {
3
3
"module" : " commonjs" ,
4
4
"esModuleInterop" : true ,
5
+ "resolveJsonModule" : true ,
5
6
"target" : " es6" ,
6
7
"noImplicitAny" : true ,
7
8
"moduleResolution" : " node" ,
Original file line number Diff line number Diff line change 84
84
resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-9.0.0.tgz#3205bcd15ada9bc681ac20bef64e9e6df88fd297"
85
85
integrity sha512-scN0hAWyLVAvLR9AyW7HoFF5sJZglyBsbPuHO4fv7JRvfmPBMfp1ozWqOf/e4wwPNxezBZXRfWzMb6iFLgEVRA==
86
86
87
+ " @types/semver@^7.3.9 " :
88
+ version "7.3.9"
89
+ resolved "https://registry.yarnpkg.com/@types/semver/-/semver-7.3.9.tgz#152c6c20a7688c30b967ec1841d31ace569863fc"
90
+ integrity sha512-L/TMpyURfBkf+o/526Zb6kd/tchUP3iBDEPjqjb+U2MAJhVRxxrmr2fwpe08E7QsV7YLcpq0tUaQ9O9x97ZIxQ==
91
+
87
92
" @typescript-eslint/eslint-plugin@^5.1.0 " :
88
93
version "5.3.1"
89
94
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.3.1.tgz#d8ff412f10f54f6364e7fd7c1e70eb6767f434c3"
@@ -669,12 +674,10 @@ globby@^11.0.4:
669
674
merge2 "^1.3.0"
670
675
slash "^3.0.0"
671
676
672
- graphql@14.6.0 :
673
- version "14.6.0"
674
- resolved "https://registry.yarnpkg.com/graphql/-/graphql-14.6.0.tgz#57822297111e874ea12f5cd4419616930cd83e49"
675
- integrity sha512-VKzfvHEKybTKjQVpTFrA5yUq2S9ihcZvfJAtsDBBCuV6wauPu1xl/f9ehgVf0FcEJJs4vz6ysb/ZMkGigQZseg==
676
- dependencies :
677
- iterall "^1.2.2"
677
+ " graphql@~14.6.0 || ~15.0.0 || ~16.0.0 " :
678
+ version "16.0.1"
679
+ resolved "https://registry.yarnpkg.com/graphql/-/graphql-16.0.1.tgz#93a13cd4e0e38ca8d0832e79614c8578bfd34f10"
680
+ integrity sha512-oPvCuu6dlLdiz8gZupJ47o1clgb72r1u8NDBcQYjcV6G/iEdmE11B1bBlkhXRvV0LisP/SXRFP7tT6AgaTjpzg==
678
681
679
682
growl@1.10.5 :
680
683
version "1.10.5"
@@ -771,11 +774,6 @@ isexe@^2.0.0:
771
774
resolved "https://registry.yarnpkg.com/isexe/-/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10"
772
775
integrity sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=
773
776
774
- iterall@^1.2.2 :
775
- version "1.3.0"
776
- resolved "https://registry.yarnpkg.com/iterall/-/iterall-1.3.0.tgz#afcb08492e2915cbd8a0884eb93a8c94d0d72fea"
777
- integrity sha512-QZ9qOMdF+QLHxy1QIpUHUU1D5pS2CG2P69LF6L6CPjPYA/XMOmKV3PZpawHoAjHNyB0swdVTRxdYT4tbBbxqwg==
778
-
779
777
js-yaml@4.1.0, js-yaml@^4.1.0 :
780
778
version "4.1.0"
781
779
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-4.1.0.tgz#c1fb65f8f5017901cdd2c951864ba18458a10602"
You can’t perform that action at this time.
0 commit comments