-
-
Notifications
You must be signed in to change notification settings - Fork 796
/
schema-from-json.spec.ts
50 lines (47 loc) · 1.99 KB
/
schema-from-json.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { loadSchema, loadSchemaSync } from '@graphql-tools/load';
import { JsonFileLoader } from '@graphql-tools/json-file-loader';
import { isSchema, GraphQLObjectType, GraphQLInterfaceType } from 'graphql';
import { runTests, useMonorepo } from '../../../../testing/utils';
const monorepo = useMonorepo({
dirname: __dirname,
});
describe('Schema From Export', () => {
monorepo.correctCWD();
runTests({
async: loadSchema,
sync: loadSchemaSync
})(load => {
it('should load the schema correctly from an introspection file', async () => {
const schema = await load('./tests/loaders/schema/test-files/githunt.json', {
loaders: [new JsonFileLoader()]
});
expect(isSchema(schema)).toBeTruthy();
});
it('should load the schema with correct descriptions', async () => {
const schema = await load('./tests/loaders/schema/test-files/githunt.json', {
loaders: [new JsonFileLoader()]
});
expect(isSchema(schema)).toBeTruthy();
const introspectionSchema = require('./test-files/githunt.json').__schema;
for (const typeName in schema.getTypeMap()) {
if (!typeName.startsWith('_')) {
const type = schema.getType(typeName);
const introspectionType = introspectionSchema.types.find((t: { name: string; }) => t.name === typeName);
if (type.description || introspectionType.description) {
expect(type.description).toBe(introspectionType.description);
}
if ('getFields' in type) {
const fieldMap = type.getFields();
for (const fieldName in fieldMap) {
const field = fieldMap[fieldName];
const introspectionField = introspectionType.fields.find((f: { name: string; }) => f.name === fieldName);
if (field.description || introspectionField.description) {
expect(field.description.trim()).toBe(introspectionField.description.trim());
}
}
}
}
}
});
})
});