forked from graphql/graphql-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NoDeprecatedCustomRule-test.js
119 lines (105 loc) · 3.12 KB
/
NoDeprecatedCustomRule-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
// @flow strict
import { describe, it } from 'mocha';
import { buildSchema } from '../../utilities/buildASTSchema';
import { NoDeprecatedCustomRule } from '../rules/custom/NoDeprecatedCustomRule';
import { expectValidationErrorsWithSchema } from './harness';
function expectErrors(queryStr) {
return expectValidationErrorsWithSchema(
schema,
NoDeprecatedCustomRule,
queryStr,
);
}
function expectValid(queryStr) {
expectErrors(queryStr).to.deep.equal([]);
}
const schema = buildSchema(`
enum EnumType {
NORMAL_VALUE
DEPRECATED_VALUE @deprecated(reason: "Some enum reason.")
DEPRECATED_VALUE_WITH_NO_REASON @deprecated
}
type Query {
normalField(enumArg: [EnumType]): String
deprecatedField: String @deprecated(reason: "Some field reason.")
deprecatedFieldWithNoReason: String @deprecated
}
`);
describe('Validate: no deprecated', () => {
it('ignores fields and enum values that are not deprecated', () => {
expectValid(`
{
normalField(enumArg: [NORMAL_VALUE])
}
`);
});
it('ignores unknown fields and enum values', () => {
expectValid(`
fragment UnknownFragment on UnknownType {
unknownField(unknownArg: UNKNOWN_VALUE)
}
fragment QueryFragment on Query {
unknownField(unknownArg: UNKNOWN_VALUE)
normalField(enumArg: UNKNOWN_VALUE)
}
`);
});
it('reports error when a deprecated field is selected', () => {
expectErrors(`
{
normalField
deprecatedField
deprecatedFieldWithNoReason
}
`).to.deep.equal([
{
message:
'The field Query.deprecatedField is deprecated. Some field reason.',
locations: [{ line: 4, column: 9 }],
},
{
message:
'The field Query.deprecatedFieldWithNoReason is deprecated. No longer supported',
locations: [{ line: 5, column: 9 }],
},
]);
});
it('reports error when a deprecated enum value is used', () => {
expectErrors(`
{
normalField(enumArg: [NORMAL_VALUE, DEPRECATED_VALUE])
normalField(enumArg: [DEPRECATED_VALUE_WITH_NO_REASON])
}
`).to.deep.equal([
{
message:
'The enum value "EnumType.DEPRECATED_VALUE" is deprecated. Some enum reason.',
locations: [{ line: 3, column: 45 }],
},
{
message:
'The enum value "EnumType.DEPRECATED_VALUE_WITH_NO_REASON" is deprecated. No longer supported',
locations: [{ line: 4, column: 31 }],
},
]);
});
it('reports error when a deprecated field is selected or an enum value is used inside a fragment', () => {
expectErrors(`
fragment QueryFragment on Query {
deprecatedField
normalField(enumArg: [NORMAL_VALUE, DEPRECATED_VALUE])
}
`).to.deep.equal([
{
message:
'The field Query.deprecatedField is deprecated. Some field reason.',
locations: [{ line: 3, column: 9 }],
},
{
message:
'The enum value "EnumType.DEPRECATED_VALUE" is deprecated. Some enum reason.',
locations: [{ line: 4, column: 45 }],
},
]);
});
});