@@ -10,6 +10,7 @@ import {
10
10
TypeInfo ,
11
11
visit ,
12
12
visitWithTypeInfo ,
13
+ buildSchema
13
14
} from 'graphql' ;
14
15
15
16
import { expect } from 'chai' ;
@@ -254,11 +255,16 @@ describe('directiveEstimator analysis', () => {
254
255
const codeFirstSchema = new GraphQLSchema ( {
255
256
directives : [ complexityDirective ]
256
257
} ) ;
257
-
258
- const printedCodeFirstSchema = printSchema ( codeFirstSchema ) . trim ( ) ;
259
- const printedComplexityDirective = print ( schema . getDirective ( 'complexity' ) . astNode ) . trim ( ) ;
260
258
261
- expect ( printedCodeFirstSchema ) . to . equal ( printedComplexityDirective ) ;
259
+ // rebuilding code first schema
260
+ // graphql-js <= 14 prints descriptions in different ways printSchema(schema) vs print(astNode)
261
+ // and directive from code first schema has no astNode
262
+ const builtCodeFirstSchema = buildSchema ( printSchema ( codeFirstSchema ) ) ;
263
+
264
+ const printedSchemaFirstDirective = print ( schema . getDirective ( 'complexity' ) . astNode ) ;
265
+ const printedCodeFirstDirective = print ( builtCodeFirstSchema . getDirective ( 'complexity' ) . astNode ) ;
266
+
267
+ expect ( printedSchemaFirstDirective ) . to . equal ( printedCodeFirstDirective ) ;
262
268
} ) ;
263
269
264
270
it ( 'should create complexity directive with configured name' , ( ) => {
@@ -267,9 +273,14 @@ describe('directiveEstimator analysis', () => {
267
273
directives : [ complexityDirective ]
268
274
} ) ;
269
275
270
- const printedCodeFirstSchema = printSchema ( codeFirstSchema ) . trim ( ) ;
271
- const printedComplexityDirective = print ( schema . getDirective ( 'cost' ) . astNode ) . trim ( ) ;
276
+ // rebuilding code first schema
277
+ // graphql-js <= 14 prints descriptions in different ways printSchema(schema) vs print(astNode)
278
+ // and directive from code first schema has no astNode
279
+ const builtCodeFirstSchema = buildSchema ( printSchema ( codeFirstSchema ) ) ;
280
+
281
+ const printedSchemaFirstDirective = print ( schema . getDirective ( 'cost' ) . astNode ) ;
282
+ const printedCodeFirstDirective = print ( builtCodeFirstSchema . getDirective ( 'cost' ) . astNode ) ;
272
283
273
- expect ( printedCodeFirstSchema ) . to . equal ( printedComplexityDirective ) ;
284
+ expect ( printedSchemaFirstDirective ) . to . equal ( printedCodeFirstDirective ) ;
274
285
} ) ;
275
286
} ) ;
0 commit comments