Skip to content

Commit 24fa31a

Browse files
Simplify SDLs used in 'buidSchema'/`extendSchema' tests (#1964)
1 parent 2fe2025 commit 24fa31a

File tree

2 files changed

+19
-72
lines changed

2 files changed

+19
-72
lines changed

src/utilities/__tests__/buildASTSchema-test.js

Lines changed: 10 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,7 @@ describe('Schema Builder', () => {
110110
});
111111

112112
it('include standard type only if it is used', () => {
113-
const schema = buildSchema(`
114-
type Query {
115-
str: String
116-
}
117-
`);
113+
const schema = buildSchema('type Query');
118114

119115
// String and Boolean are always included through introspection types
120116
expect(schema.getType('Int')).to.equal(undefined);
@@ -125,10 +121,6 @@ describe('Schema Builder', () => {
125121
it('With directives', () => {
126122
const sdl = dedent`
127123
directive @foo(arg: Int) on FIELD
128-
129-
type Query {
130-
str: String
131-
}
132124
`;
133125
expect(cycleSDL(sdl)).to.equal(sdl);
134126
});
@@ -186,11 +178,7 @@ describe('Schema Builder', () => {
186178
});
187179

188180
it('Maintains @skip & @include', () => {
189-
const schema = buildSchema(`
190-
type Query {
191-
str: String
192-
}
193-
`);
181+
const schema = buildSchema('type Query');
194182

195183
expect(schema.getDirectives()).to.have.lengthOf(3);
196184
expect(schema.getDirective('skip')).to.equal(GraphQLSkipDirective);
@@ -205,10 +193,6 @@ describe('Schema Builder', () => {
205193
directive @skip on FIELD
206194
directive @include on FIELD
207195
directive @deprecated on FIELD_DEFINITION
208-
209-
type Query {
210-
str: String
211-
}
212196
`);
213197

214198
expect(schema.getDirectives()).to.have.lengthOf(3);
@@ -224,10 +208,6 @@ describe('Schema Builder', () => {
224208
it('Adding directives maintains @skip & @include', () => {
225209
const schema = buildSchema(`
226210
directive @foo(arg: Int) on FIELD
227-
228-
type Query {
229-
str: String
230-
}
231211
`);
232212

233213
expect(schema.getDirectives()).to.have.lengthOf(4);
@@ -261,10 +241,6 @@ describe('Schema Builder', () => {
261241

262242
it('Two types circular', () => {
263243
const sdl = dedent`
264-
schema {
265-
query: TypeOne
266-
}
267-
268244
type TypeOne {
269245
str: String
270246
typeTwo: TypeTwo
@@ -802,9 +778,9 @@ describe('Schema Builder', () => {
802778
mutation: SomeMutation
803779
subscription: SomeSubscription
804780
}
805-
type SomeQuery { str: String }
806-
type SomeMutation { str: String }
807-
type SomeSubscription { str: String }
781+
type SomeQuery
782+
type SomeMutation
783+
type SomeSubscription
808784
`);
809785

810786
expect(schema.getQueryType()).to.include({ name: 'SomeQuery' });
@@ -816,9 +792,9 @@ describe('Schema Builder', () => {
816792

817793
it('Default root operation type names', () => {
818794
const schema = buildSchema(`
819-
type Query { str: String }
820-
type Mutation { str: String }
821-
type Subscription { str: String }
795+
type Query
796+
type Mutation
797+
type Subscription
822798
`);
823799

824800
expect(schema.getQueryType()).to.include({ name: 'Query' });
@@ -827,12 +803,8 @@ describe('Schema Builder', () => {
827803
});
828804

829805
it('can build invalid schema', () => {
830-
const schema = buildSchema(`
831-
# Invalid schema, because it is missing query root type
832-
type Mutation {
833-
str: String
834-
}
835-
`);
806+
// Invalid schema, because it is missing query root type
807+
const schema = buildSchema('type Mutation');
836808
const errors = validateSchema(schema);
837809
expect(errors).to.have.lengthOf.above(0);
838810
});

src/utilities/__tests__/extendSchema-test.js

Lines changed: 9 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -268,11 +268,7 @@ describe('extendSchema', () => {
268268
});
269269

270270
it('extends objects with standard type fields', () => {
271-
const schema = buildSchema(`
272-
type Query {
273-
str: String
274-
}
275-
`);
271+
const schema = buildSchema('type Query');
276272

277273
// String and Boolean are always included through introspection types
278274
expect(schema.getType('Int')).to.equal(undefined);
@@ -1196,9 +1192,7 @@ describe('extendSchema', () => {
11961192
describe('can add additional root operation types', () => {
11971193
it('does not automatically include common root type names', () => {
11981194
const schema = extendTestSchema(`
1199-
type Mutation {
1200-
doSomething: String
1201-
}
1195+
type Mutation
12021196
`);
12031197
expect(schema.getMutationType()).to.equal(null);
12041198
});
@@ -1227,9 +1221,7 @@ describe('extendSchema', () => {
12271221
mutation: Mutation
12281222
}
12291223
1230-
type Mutation {
1231-
doSomething: String
1232-
}
1224+
type Mutation
12331225
`);
12341226
const mutationType = schema.getMutationType();
12351227
expect(mutationType).to.include({ name: 'Mutation' });
@@ -1242,13 +1234,8 @@ describe('extendSchema', () => {
12421234
subscription: Subscription
12431235
}
12441236
1245-
type Mutation {
1246-
doSomething: String
1247-
}
1248-
1249-
type Subscription {
1250-
hearSomething: String
1251-
}
1237+
type Mutation
1238+
type Subscription
12521239
`);
12531240
const mutationType = schema.getMutationType();
12541241
const subscriptionType = schema.getSubscriptionType();
@@ -1261,18 +1248,12 @@ describe('extendSchema', () => {
12611248
extend schema {
12621249
mutation: Mutation
12631250
}
1251+
type Mutation
12641252
12651253
extend schema {
12661254
subscription: Subscription
12671255
}
1268-
1269-
type Mutation {
1270-
doSomething: String
1271-
}
1272-
1273-
type Subscription {
1274-
hearSomething: String
1275-
}
1256+
type Subscription
12761257
`);
12771258
const mutationType = schema.getMutationType();
12781259
const subscriptionType = schema.getSubscriptionType();
@@ -1285,18 +1266,12 @@ describe('extendSchema', () => {
12851266
extend schema {
12861267
mutation: Mutation
12871268
}
1269+
type Mutation
12881270
12891271
extend schema {
12901272
subscription: Subscription
12911273
}
1292-
1293-
type Mutation {
1294-
doSomething: String
1295-
}
1296-
1297-
type Subscription {
1298-
hearSomething: String
1299-
}
1274+
type Subscription
13001275
`);
13011276

13021277
const ast = parse(`

0 commit comments

Comments
 (0)