Skip to content

Commit 34b7ced

Browse files
Cleanup unnecessary Query types from printSchema tests (#1706)
1 parent 56ad8a1 commit 34b7ced

File tree

1 file changed

+14
-126
lines changed

1 file changed

+14
-126
lines changed

src/utilities/__tests__/schemaPrinter-test.js

Lines changed: 14 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import { describe, it } from 'mocha';
1111
import { expect } from 'chai';
1212
import dedent from '../../jsutils/dedent';
13-
import invariant from '../../jsutils/invariant';
1413
import { printSchema, printIntrospectionSchema } from '../schemaPrinter';
1514
import { buildSchema } from '../buildASTSchema';
1615
import {
@@ -127,21 +126,12 @@ describe('Type System Printer', () => {
127126
fields: { str: { type: GraphQLString } },
128127
});
129128

130-
const Query = new GraphQLObjectType({
131-
name: 'Query',
132-
fields: { foo: { type: FooType } },
133-
});
134-
135-
const Schema = new GraphQLSchema({ query: Query });
129+
const Schema = new GraphQLSchema({ types: [FooType] });
136130
const output = printForTest(Schema);
137131
expect(output).to.equal(dedent`
138132
type Foo {
139133
str: String
140134
}
141-
142-
type Query {
143-
foo: Foo
144-
}
145135
`);
146136
});
147137

@@ -304,15 +294,7 @@ describe('Type System Printer', () => {
304294
interfaces: [FooType],
305295
});
306296

307-
const Query = new GraphQLObjectType({
308-
name: 'Query',
309-
fields: { bar: { type: BarType } },
310-
});
311-
312-
const Schema = new GraphQLSchema({
313-
query: Query,
314-
types: [BarType],
315-
});
297+
const Schema = new GraphQLSchema({ types: [BarType] });
316298
const output = printForTest(Schema);
317299
expect(output).to.equal(dedent`
318300
type Bar implements Foo {
@@ -322,10 +304,6 @@ describe('Type System Printer', () => {
322304
interface Foo {
323305
str: String
324306
}
325-
326-
type Query {
327-
bar: Bar
328-
}
329307
`);
330308
});
331309

@@ -349,15 +327,7 @@ describe('Type System Printer', () => {
349327
interfaces: [FooType, BaazType],
350328
});
351329

352-
const Query = new GraphQLObjectType({
353-
name: 'Query',
354-
fields: { bar: { type: BarType } },
355-
});
356-
357-
const Schema = new GraphQLSchema({
358-
query: Query,
359-
types: [BarType],
360-
});
330+
const Schema = new GraphQLSchema({ types: [BarType] });
361331
const output = printForTest(Schema);
362332
expect(output).to.equal(dedent`
363333
interface Baaz {
@@ -372,10 +342,6 @@ describe('Type System Printer', () => {
372342
interface Foo {
373343
str: String
374344
}
375-
376-
type Query {
377-
bar: Bar
378-
}
379345
`);
380346
});
381347

@@ -404,15 +370,7 @@ describe('Type System Printer', () => {
404370
types: [FooType, BarType],
405371
});
406372

407-
const Query = new GraphQLObjectType({
408-
name: 'Query',
409-
fields: {
410-
single: { type: SingleUnion },
411-
multiple: { type: MultipleUnion },
412-
},
413-
});
414-
415-
const Schema = new GraphQLSchema({ query: Query });
373+
const Schema = new GraphQLSchema({ types: [SingleUnion, MultipleUnion] });
416374
const output = printForTest(Schema);
417375
expect(output).to.equal(dedent`
418376
type Bar {
@@ -425,11 +383,6 @@ describe('Type System Printer', () => {
425383
426384
union MultipleUnion = Foo | Bar
427385
428-
type Query {
429-
single: SingleUnion
430-
multiple: MultipleUnion
431-
}
432-
433386
union SingleUnion = Foo
434387
`);
435388
});
@@ -442,80 +395,41 @@ describe('Type System Printer', () => {
442395
},
443396
});
444397

445-
const Query = new GraphQLObjectType({
446-
name: 'Query',
447-
fields: {
448-
str: {
449-
type: GraphQLString,
450-
args: { argOne: { type: InputType } },
451-
},
452-
},
453-
});
454-
455-
const Schema = new GraphQLSchema({ query: Query });
398+
const Schema = new GraphQLSchema({ types: [InputType] });
456399
const output = printForTest(Schema);
457400
expect(output).to.equal(dedent`
458401
input InputType {
459402
int: Int
460403
}
461-
462-
type Query {
463-
str(argOne: InputType): String
464-
}
465404
`);
466405
});
467406

468407
it('Custom Scalar', () => {
469408
const OddType = new GraphQLScalarType({
470409
name: 'Odd',
471-
serialize(value) {
472-
invariant(typeof value === 'number');
473-
return value % 2 === 1 ? value : null;
474-
},
475-
});
476-
477-
const Query = new GraphQLObjectType({
478-
name: 'Query',
479-
fields: {
480-
odd: { type: OddType },
481-
},
410+
serialize() {},
482411
});
483412

484-
const Schema = new GraphQLSchema({ query: Query });
413+
const Schema = new GraphQLSchema({ types: [OddType] });
485414
const output = printForTest(Schema);
486415
expect(output).to.equal(dedent`
487416
scalar Odd
488-
489-
type Query {
490-
odd: Odd
491-
}
492417
`);
493418
});
494419

495420
it('Enum', () => {
496421
const RGBType = new GraphQLEnumType({
497422
name: 'RGB',
498423
values: {
499-
RED: { value: 0 },
500-
GREEN: { value: 1 },
501-
BLUE: { value: 2 },
502-
},
503-
});
504-
505-
const Query = new GraphQLObjectType({
506-
name: 'Query',
507-
fields: {
508-
rgb: { type: RGBType },
424+
RED: {},
425+
GREEN: {},
426+
BLUE: {},
509427
},
510428
});
511429

512-
const Schema = new GraphQLSchema({ query: Query });
430+
const Schema = new GraphQLSchema({ types: [RGBType] });
513431
const output = printForTest(Schema);
514432
expect(output).to.equal(dedent`
515-
type Query {
516-
rgb: RGB
517-
}
518-
519433
enum RGB {
520434
RED
521435
GREEN
@@ -525,29 +439,15 @@ describe('Type System Printer', () => {
525439
});
526440

527441
it('Prints custom directives', () => {
528-
const Query = new GraphQLObjectType({
529-
name: 'Query',
530-
fields: {
531-
field: { type: GraphQLString },
532-
},
533-
});
534-
535442
const CustomDirective = new GraphQLDirective({
536443
name: 'customDirective',
537444
locations: [DirectiveLocation.FIELD],
538445
});
539446

540-
const Schema = new GraphQLSchema({
541-
query: Query,
542-
directives: [CustomDirective],
543-
});
447+
const Schema = new GraphQLSchema({ directives: [CustomDirective] });
544448
const output = printForTest(Schema);
545449
expect(output).to.equal(dedent`
546450
directive @customDirective on FIELD
547-
548-
type Query {
549-
field: String
550-
}
551451
`);
552452
});
553453

@@ -609,13 +509,7 @@ describe('Type System Printer', () => {
609509
});
610510

611511
it('Print Introspection Schema', () => {
612-
const Query = new GraphQLObjectType({
613-
name: 'Query',
614-
fields: {
615-
onlyField: { type: GraphQLString },
616-
},
617-
});
618-
const Schema = new GraphQLSchema({ query: Query });
512+
const Schema = new GraphQLSchema({});
619513
const output = printIntrospectionSchema(Schema);
620514
const introspectionSchema = dedent`
621515
"""
@@ -848,13 +742,7 @@ describe('Type System Printer', () => {
848742
});
849743

850744
it('Print Introspection Schema with comment descriptions', () => {
851-
const Query = new GraphQLObjectType({
852-
name: 'Query',
853-
fields: {
854-
onlyField: { type: GraphQLString },
855-
},
856-
});
857-
const Schema = new GraphQLSchema({ query: Query });
745+
const Schema = new GraphQLSchema({});
858746
const output = printIntrospectionSchema(Schema, {
859747
commentDescriptions: true,
860748
});

0 commit comments

Comments
 (0)