Skip to content

Commit 7e6d9f7

Browse files
committed
Failing test for schema printing
1 parent 76e47fc commit 7e6d9f7

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed

src/__testUtils__/viralSDL.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
export const viralSDL = `\
2+
schema {
3+
query: Query
4+
}
5+
6+
type Query {
7+
viruses: [Virus!]
8+
}
9+
10+
type Virus {
11+
name: String!
12+
knownMutations: [Mutation!]!
13+
}
14+
15+
type Mutation {
16+
name: String!
17+
geneSequence: String!
18+
}\
19+
`;

src/__testUtils__/viralSchema.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import {
2+
GraphQLList,
3+
GraphQLNonNull,
4+
GraphQLObjectType,
5+
} from '../type/definition.js';
6+
import { GraphQLString } from '../type/scalars.js';
7+
import { GraphQLSchema } from '../type/schema.js';
8+
9+
const Mutation = new GraphQLObjectType({
10+
name: 'Mutation',
11+
fields: {
12+
name: {
13+
type: new GraphQLNonNull(GraphQLString),
14+
},
15+
geneSequence: {
16+
type: new GraphQLNonNull(GraphQLString),
17+
},
18+
},
19+
});
20+
21+
const Virus = new GraphQLObjectType({
22+
name: 'Virus',
23+
fields: {
24+
name: {
25+
type: new GraphQLNonNull(GraphQLString),
26+
},
27+
knownMutations: {
28+
type: new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(Mutation))),
29+
},
30+
},
31+
});
32+
33+
const Query = new GraphQLObjectType({
34+
name: 'Query',
35+
fields: {
36+
viruses: {
37+
type: new GraphQLList(new GraphQLNonNull(Virus)),
38+
},
39+
},
40+
});
41+
42+
export const viralSchema = new GraphQLSchema({
43+
query: Query,
44+
});

src/utilities/__tests__/printSchema-test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { expect } from 'chai';
22
import { describe, it } from 'mocha';
33

44
import { dedent, dedentString } from '../../__testUtils__/dedent.js';
5+
import { viralSchema } from '../../__testUtils__/viralSchema.js';
6+
import { viralSDL } from '../../__testUtils__/viralSDL.js';
57

68
import { DirectiveLocation } from '../../language/directiveLocation.js';
79

@@ -867,4 +869,8 @@ describe('Type System Printer', () => {
867869
}
868870
`);
869871
});
872+
it('prints viral schema correctly', () => {
873+
const printed = printSchema(viralSchema);
874+
expect(printed).to.equal(viralSDL);
875+
});
870876
});

0 commit comments

Comments
 (0)