Skip to content

Commit

Permalink
Simplify SDLs used in 'buidSchema'/`extendSchema' tests (#1964)
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov committed Jun 9, 2019
1 parent 2fe2025 commit 24fa31a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 72 deletions.
48 changes: 10 additions & 38 deletions src/utilities/__tests__/buildASTSchema-test.js
Expand Up @@ -110,11 +110,7 @@ describe('Schema Builder', () => {
});

it('include standard type only if it is used', () => {
const schema = buildSchema(`
type Query {
str: String
}
`);
const schema = buildSchema('type Query');

// String and Boolean are always included through introspection types
expect(schema.getType('Int')).to.equal(undefined);
Expand All @@ -125,10 +121,6 @@ describe('Schema Builder', () => {
it('With directives', () => {
const sdl = dedent`
directive @foo(arg: Int) on FIELD
type Query {
str: String
}
`;
expect(cycleSDL(sdl)).to.equal(sdl);
});
Expand Down Expand Up @@ -186,11 +178,7 @@ describe('Schema Builder', () => {
});

it('Maintains @skip & @include', () => {
const schema = buildSchema(`
type Query {
str: String
}
`);
const schema = buildSchema('type Query');

expect(schema.getDirectives()).to.have.lengthOf(3);
expect(schema.getDirective('skip')).to.equal(GraphQLSkipDirective);
Expand All @@ -205,10 +193,6 @@ describe('Schema Builder', () => {
directive @skip on FIELD
directive @include on FIELD
directive @deprecated on FIELD_DEFINITION
type Query {
str: String
}
`);

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

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

it('Two types circular', () => {
const sdl = dedent`
schema {
query: TypeOne
}
type TypeOne {
str: String
typeTwo: TypeTwo
Expand Down Expand Up @@ -802,9 +778,9 @@ describe('Schema Builder', () => {
mutation: SomeMutation
subscription: SomeSubscription
}
type SomeQuery { str: String }
type SomeMutation { str: String }
type SomeSubscription { str: String }
type SomeQuery
type SomeMutation
type SomeSubscription
`);

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

it('Default root operation type names', () => {
const schema = buildSchema(`
type Query { str: String }
type Mutation { str: String }
type Subscription { str: String }
type Query
type Mutation
type Subscription
`);

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

it('can build invalid schema', () => {
const schema = buildSchema(`
# Invalid schema, because it is missing query root type
type Mutation {
str: String
}
`);
// Invalid schema, because it is missing query root type
const schema = buildSchema('type Mutation');
const errors = validateSchema(schema);
expect(errors).to.have.lengthOf.above(0);
});
Expand Down
43 changes: 9 additions & 34 deletions src/utilities/__tests__/extendSchema-test.js
Expand Up @@ -268,11 +268,7 @@ describe('extendSchema', () => {
});

it('extends objects with standard type fields', () => {
const schema = buildSchema(`
type Query {
str: String
}
`);
const schema = buildSchema('type Query');

// String and Boolean are always included through introspection types
expect(schema.getType('Int')).to.equal(undefined);
Expand Down Expand Up @@ -1196,9 +1192,7 @@ describe('extendSchema', () => {
describe('can add additional root operation types', () => {
it('does not automatically include common root type names', () => {
const schema = extendTestSchema(`
type Mutation {
doSomething: String
}
type Mutation
`);
expect(schema.getMutationType()).to.equal(null);
});
Expand Down Expand Up @@ -1227,9 +1221,7 @@ describe('extendSchema', () => {
mutation: Mutation
}
type Mutation {
doSomething: String
}
type Mutation
`);
const mutationType = schema.getMutationType();
expect(mutationType).to.include({ name: 'Mutation' });
Expand All @@ -1242,13 +1234,8 @@ describe('extendSchema', () => {
subscription: Subscription
}
type Mutation {
doSomething: String
}
type Subscription {
hearSomething: String
}
type Mutation
type Subscription
`);
const mutationType = schema.getMutationType();
const subscriptionType = schema.getSubscriptionType();
Expand All @@ -1261,18 +1248,12 @@ describe('extendSchema', () => {
extend schema {
mutation: Mutation
}
type Mutation
extend schema {
subscription: Subscription
}
type Mutation {
doSomething: String
}
type Subscription {
hearSomething: String
}
type Subscription
`);
const mutationType = schema.getMutationType();
const subscriptionType = schema.getSubscriptionType();
Expand All @@ -1285,18 +1266,12 @@ describe('extendSchema', () => {
extend schema {
mutation: Mutation
}
type Mutation
extend schema {
subscription: Subscription
}
type Mutation {
doSomething: String
}
type Subscription {
hearSomething: String
}
type Subscription
`);

const ast = parse(`
Expand Down

0 comments on commit 24fa31a

Please sign in to comment.