forked from graphql/graphql-js
-
Notifications
You must be signed in to change notification settings - Fork 5
/
getIntrospectionQuery-test.js
119 lines (93 loc) · 3.16 KB
/
getIntrospectionQuery-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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import { expect } from 'chai';
import { describe, it } from 'mocha';
import type { IntrospectionOptions } from '../getIntrospectionQuery';
import { getIntrospectionQuery } from '../getIntrospectionQuery';
function expectIntrospectionQuery(options?: IntrospectionOptions) {
const query = getIntrospectionQuery(options);
return {
toMatch(name: string, times: number = 1): void {
const pattern = toRegExp(name);
expect(query).to.match(pattern);
expect(query.match(pattern)).to.have.lengthOf(times);
},
toNotMatch(name: string): void {
expect(query).to.not.match(toRegExp(name));
},
};
function toRegExp(name: string): RegExp {
return new RegExp('\\b' + name + '\\b', 'g');
}
}
describe('getIntrospectionQuery', () => {
it('skip all "description" fields', () => {
expectIntrospectionQuery().toMatch('description', 5);
expectIntrospectionQuery({ descriptions: true }).toMatch('description', 5);
expectIntrospectionQuery({ descriptions: false }).toNotMatch('description');
});
it('include "isRepeatable" field on directives', () => {
expectIntrospectionQuery().toNotMatch('isRepeatable');
expectIntrospectionQuery({ directiveIsRepeatable: true }).toMatch(
'isRepeatable',
);
expectIntrospectionQuery({ directiveIsRepeatable: false }).toNotMatch(
'isRepeatable',
);
});
it('include "description" field on schema', () => {
expectIntrospectionQuery().toMatch('description', 5);
expectIntrospectionQuery({ schemaDescription: false }).toMatch(
'description',
5,
);
expectIntrospectionQuery({ schemaDescription: true }).toMatch(
'description',
6,
);
expectIntrospectionQuery({
descriptions: false,
schemaDescription: true,
}).toNotMatch('description');
});
it('include "specifiedByUrl" field', () => {
expectIntrospectionQuery().toNotMatch('specifiedByUrl');
expectIntrospectionQuery({ specifiedByUrl: true }).toMatch(
'specifiedByUrl',
);
expectIntrospectionQuery({ specifiedByUrl: false }).toNotMatch(
'specifiedByUrl',
);
});
it('include "isDeprecated" field on input values', () => {
expectIntrospectionQuery().toMatch('isDeprecated', 2);
expectIntrospectionQuery({ inputValueDeprecation: true }).toMatch(
'isDeprecated',
3,
);
expectIntrospectionQuery({ inputValueDeprecation: false }).toMatch(
'isDeprecated',
2,
);
});
it('include "deprecationReason" field on input values', () => {
expectIntrospectionQuery().toMatch('deprecationReason', 2);
expectIntrospectionQuery({ inputValueDeprecation: true }).toMatch(
'deprecationReason',
3,
);
expectIntrospectionQuery({ inputValueDeprecation: false }).toMatch(
'deprecationReason',
2,
);
});
it('include deprecated input field and args', () => {
expectIntrospectionQuery().toMatch('includeDeprecated: true', 2);
expectIntrospectionQuery({ inputValueDeprecation: true }).toMatch(
'includeDeprecated: true',
5,
);
expectIntrospectionQuery({ inputValueDeprecation: false }).toMatch(
'includeDeprecated: true',
2,
);
});
});