Skip to content

Commit 210f543

Browse files
committed
Export complexity directive
1 parent aabe1ce commit 210f543

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

src/estimators/directive/__tests__/directiveEstimator-test.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
TypeInfo,
1111
visit,
1212
visitWithTypeInfo,
13+
buildSchema
1314
} from 'graphql';
1415

1516
import {expect} from 'chai';
@@ -254,11 +255,16 @@ describe('directiveEstimator analysis', () => {
254255
const codeFirstSchema = new GraphQLSchema({
255256
directives: [complexityDirective]
256257
});
257-
258-
const printedCodeFirstSchema = printSchema(codeFirstSchema).trim();
259-
const printedComplexityDirective = print(schema.getDirective('complexity').astNode).trim();
260258

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);
262268
});
263269

264270
it('should create complexity directive with configured name', () => {
@@ -267,9 +273,14 @@ describe('directiveEstimator analysis', () => {
267273
directives: [complexityDirective]
268274
});
269275

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);
272283

273-
expect(printedCodeFirstSchema).to.equal(printedComplexityDirective);
284+
expect(printedSchemaFirstDirective).to.equal(printedCodeFirstDirective);
274285
});
275286
});

0 commit comments

Comments
 (0)