Skip to content

Commit 0b7625f

Browse files
TypeInfo-test: remove dependency on harness schema for validation tests (#3175)
1 parent d39a7b5 commit 0b7625f

File tree

1 file changed

+43
-5
lines changed

1 file changed

+43
-5
lines changed

src/utilities/__tests__/TypeInfo-test.ts

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,57 @@ import { parse, parseValue } from '../../language/parser';
77
import { print } from '../../language/printer';
88
import { visit } from '../../language/visitor';
99

10+
import { GraphQLSchema } from '../../type/schema';
1011
import { getNamedType, isCompositeType } from '../../type/definition';
1112

1213
import { buildSchema } from '../buildASTSchema';
1314
import { TypeInfo, visitWithTypeInfo } from '../TypeInfo';
1415

15-
import { testSchema } from '../../validation/__tests__/harness';
16+
const testSchema = buildSchema(`
17+
interface Pet {
18+
name: String
19+
}
20+
21+
type Dog implements Pet {
22+
name: String
23+
}
24+
25+
type Cat implements Pet {
26+
name: String
27+
}
28+
29+
type Human {
30+
name: String
31+
pets: [Pet]
32+
}
33+
34+
type Alien {
35+
name(surname: Boolean): String
36+
}
37+
38+
type QueryRoot {
39+
human(id: ID): Human
40+
alien: Alien
41+
}
42+
43+
schema {
44+
query: QueryRoot
45+
}
46+
`);
1647

1748
describe('TypeInfo', () => {
49+
const schema = new GraphQLSchema({});
50+
1851
it('can be Object.toStringified', () => {
19-
const typeInfo = new TypeInfo(testSchema);
52+
const typeInfo = new TypeInfo(schema);
2053

2154
expect(Object.prototype.toString.call(typeInfo)).to.equal(
2255
'[object TypeInfo]',
2356
);
2457
});
2558

2659
it('allow all methods to be called before entering any node', () => {
27-
const typeInfo = new TypeInfo(testSchema);
60+
const typeInfo = new TypeInfo(schema);
2861

2962
expect(typeInfo.getType()).to.equal(undefined);
3063
expect(typeInfo.getParentType()).to.equal(undefined);
@@ -316,11 +349,16 @@ describe('visitWithTypeInfo', () => {
316349
});
317350

318351
it('supports traversals of input values', () => {
352+
const schema = buildSchema(`
353+
input ComplexInput {
354+
stringListField: [String]
355+
}
356+
`);
319357
const ast = parseValue('{ stringListField: ["foo"] }');
320-
const complexInputType = testSchema.getType('ComplexInput');
358+
const complexInputType = schema.getType('ComplexInput');
321359
invariant(complexInputType != null);
322360

323-
const typeInfo = new TypeInfo(testSchema, complexInputType);
361+
const typeInfo = new TypeInfo(schema, complexInputType);
324362

325363
const visited: Array<any> = [];
326364
visit(

0 commit comments

Comments
 (0)