forked from graphql/graphql-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
introspectionFromSchema-test.js
66 lines (55 loc) · 1.72 KB
/
introspectionFromSchema-test.js
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import { expect } from 'chai';
import { describe, it } from 'mocha';
import dedent from '../../__testUtils__/dedent';
import { GraphQLSchema } from '../../type/schema';
import { GraphQLString } from '../../type/scalars';
import { GraphQLObjectType } from '../../type/definition';
import type { IntrospectionQuery } from '../getIntrospectionQuery';
import { printSchema } from '../printSchema';
import { buildClientSchema } from '../buildClientSchema';
import { introspectionFromSchema } from '../introspectionFromSchema';
function introspectionToSDL(introspection: IntrospectionQuery): string {
return printSchema(buildClientSchema(introspection));
}
describe('introspectionFromSchema', () => {
const schema = new GraphQLSchema({
description: 'This is a simple schema',
query: new GraphQLObjectType({
name: 'Simple',
description: 'This is a simple type',
fields: {
string: {
type: GraphQLString,
description: 'This is a string field',
},
},
}),
});
it('converts a simple schema', () => {
const introspection = introspectionFromSchema(schema);
expect(introspectionToSDL(introspection)).to.deep.equal(dedent`
"""This is a simple schema"""
schema {
query: Simple
}
"""This is a simple type"""
type Simple {
"""This is a string field"""
string: String
}
`);
});
it('converts a simple schema without descriptions', () => {
const introspection = introspectionFromSchema(schema, {
descriptions: false,
});
expect(introspectionToSDL(introspection)).to.deep.equal(dedent`
schema {
query: Simple
}
type Simple {
string: String
}
`);
});
});