Skip to content

Commit

Permalink
Follow up to #1211
Browse files Browse the repository at this point in the history
  • Loading branch information
leebyron committed Jan 27, 2018
1 parent bd8aa36 commit 6dc634b
Showing 1 changed file with 56 additions and 71 deletions.
127 changes: 56 additions & 71 deletions src/utilities/__tests__/schemaPrinter-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,23 +123,19 @@ describe('Type System Printer', () => {
fields: { str: { type: GraphQLString } },
});

const Root = new GraphQLObjectType({
name: 'Root',
const Query = new GraphQLObjectType({
name: 'Query',
fields: { foo: { type: FooType } },
});

const Schema = new GraphQLSchema({ query: Root });
const Schema = new GraphQLSchema({ query: Query });
const output = printForTest(Schema);
expect(output).to.equal(dedent`
schema {
query: Root
}
type Foo {
str: String
}
type Root {
type Query {
foo: Foo
}
`);
Expand Down Expand Up @@ -270,6 +266,27 @@ describe('Type System Printer', () => {
`);
});

it('Prints custom query root type', () => {
const CustomQueryType = new GraphQLObjectType({
name: 'CustomQueryType',
fields: { bar: { type: GraphQLString } },
});

const Schema = new GraphQLSchema({
query: CustomQueryType,
});
const output = printForTest(Schema);
expect(output).to.equal(dedent`
schema {
query: CustomQueryType
}
type CustomQueryType {
bar: String
}
`);
});

it('Print Interface', () => {
const FooType = new GraphQLInterfaceType({
name: 'Foo',
Expand All @@ -282,21 +299,17 @@ describe('Type System Printer', () => {
interfaces: [FooType],
});

const Root = new GraphQLObjectType({
name: 'Root',
const Query = new GraphQLObjectType({
name: 'Query',
fields: { bar: { type: BarType } },
});

const Schema = new GraphQLSchema({
query: Root,
query: Query,
types: [BarType],
});
const output = printForTest(Schema);
expect(output).to.equal(dedent`
schema {
query: Root
}
type Bar implements Foo {
str: String
}
Expand All @@ -305,7 +318,7 @@ describe('Type System Printer', () => {
str: String
}
type Root {
type Query {
bar: Bar
}
`);
Expand All @@ -331,21 +344,17 @@ describe('Type System Printer', () => {
interfaces: [FooType, BaazType],
});

const Root = new GraphQLObjectType({
name: 'Root',
const Query = new GraphQLObjectType({
name: 'Query',
fields: { bar: { type: BarType } },
});

const Schema = new GraphQLSchema({
query: Root,
query: Query,
types: [BarType],
});
const output = printForTest(Schema);
expect(output).to.equal(dedent`
schema {
query: Root
}
interface Baaz {
int: Int
}
Expand All @@ -359,7 +368,7 @@ describe('Type System Printer', () => {
str: String
}
type Root {
type Query {
bar: Bar
}
`);
Expand Down Expand Up @@ -390,21 +399,17 @@ describe('Type System Printer', () => {
types: [FooType, BarType],
});

const Root = new GraphQLObjectType({
name: 'Root',
const Query = new GraphQLObjectType({
name: 'Query',
fields: {
single: { type: SingleUnion },
multiple: { type: MultipleUnion },
},
});

const Schema = new GraphQLSchema({ query: Root });
const Schema = new GraphQLSchema({ query: Query });
const output = printForTest(Schema);
expect(output).to.equal(dedent`
schema {
query: Root
}
type Bar {
str: String
}
Expand All @@ -415,7 +420,7 @@ describe('Type System Printer', () => {
union MultipleUnion = Foo | Bar
type Root {
type Query {
single: SingleUnion
multiple: MultipleUnion
}
Expand All @@ -432,8 +437,8 @@ describe('Type System Printer', () => {
},
});

const Root = new GraphQLObjectType({
name: 'Root',
const Query = new GraphQLObjectType({
name: 'Query',
fields: {
str: {
type: GraphQLString,
Expand All @@ -442,18 +447,14 @@ describe('Type System Printer', () => {
},
});

const Schema = new GraphQLSchema({ query: Root });
const Schema = new GraphQLSchema({ query: Query });
const output = printForTest(Schema);
expect(output).to.equal(dedent`
schema {
query: Root
}
input InputType {
int: Int
}
type Root {
type Query {
str(argOne: InputType): String
}
`);
Expand All @@ -467,23 +468,19 @@ describe('Type System Printer', () => {
},
});

const Root = new GraphQLObjectType({
name: 'Root',
const Query = new GraphQLObjectType({
name: 'Query',
fields: {
odd: { type: OddType },
},
});

const Schema = new GraphQLSchema({ query: Root });
const Schema = new GraphQLSchema({ query: Query });
const output = printForTest(Schema);
expect(output).to.equal(dedent`
schema {
query: Root
}
scalar Odd
type Root {
type Query {
odd: Odd
}
`);
Expand All @@ -499,29 +496,25 @@ describe('Type System Printer', () => {
},
});

const Root = new GraphQLObjectType({
name: 'Root',
const Query = new GraphQLObjectType({
name: 'Query',
fields: {
rgb: { type: RGBType },
},
});

const Schema = new GraphQLSchema({ query: Root });
const Schema = new GraphQLSchema({ query: Query });
const output = printForTest(Schema);
expect(output).to.equal(dedent`
schema {
query: Root
type Query {
rgb: RGB
}
enum RGB {
RED
GREEN
BLUE
}
type Root {
rgb: RGB
}
`);
});

Expand Down Expand Up @@ -553,19 +546,15 @@ describe('Type System Printer', () => {
});

it('Print Introspection Schema', () => {
const Root = new GraphQLObjectType({
name: 'Root',
const Query = new GraphQLObjectType({
name: 'Query',
fields: {
onlyField: { type: GraphQLString },
},
});
const Schema = new GraphQLSchema({ query: Root });
const Schema = new GraphQLSchema({ query: Query });
const output = printIntrospectionSchema(Schema);
const introspectionSchema = dedent`
schema {
query: Root
}
"""
Directs the executor to include this field or fragment only when the \`if\` argument is true.
"""
Expand Down Expand Up @@ -796,21 +785,17 @@ describe('Type System Printer', () => {
});

it('Print Introspection Schema with comment descriptions', () => {
const Root = new GraphQLObjectType({
name: 'Root',
const Query = new GraphQLObjectType({
name: 'Query',
fields: {
onlyField: { type: GraphQLString },
},
});
const Schema = new GraphQLSchema({ query: Root });
const Schema = new GraphQLSchema({ query: Query });
const output = printIntrospectionSchema(Schema, {
commentDescriptions: true,
});
const introspectionSchema = dedent`
schema {
query: Root
}
# Directs the executor to include this field or fragment only when the \`if\` argument is true.
directive @include(
# Included when true.
Expand Down

0 comments on commit 6dc634b

Please sign in to comment.