@@ -17,6 +17,103 @@ export const createPolicy = (level: RuleInstanceSeverityLevel): SchemaPolicyInpu
17
17
18
18
describe ( 'Schema policy checks' , ( ) => {
19
19
describe ( 'model: composite' , ( ) => {
20
+ it . only ( 'no-unreachable-types issue: directives are not scanned/marked as unused' , async ( ) => {
21
+ const policyObject : SchemaPolicyInput = {
22
+ rules : [
23
+ {
24
+ ruleId : 'no-unreachable-types' ,
25
+ severity : RuleInstanceSeverityLevel . Error ,
26
+ } ,
27
+ ] ,
28
+ } ;
29
+
30
+ const { tokens, policy } = await prepareProject ( ProjectType . Federation ) ;
31
+ await policy . setOrganizationSchemaPolicy ( policyObject , true ) ;
32
+ const cli = createCLI ( tokens . registry ) ;
33
+
34
+ await cli . publish ( {
35
+ sdl : /* GraphQL */ `
36
+ type Query {
37
+ a: String!
38
+ }
39
+ ` ,
40
+ serviceName : 'a' ,
41
+ serviceUrl : 'https://api.com/a' ,
42
+ expect : 'latest-composable' ,
43
+ } ) ;
44
+
45
+ await cli . publish ( {
46
+ sdl : /* GraphQL */ `
47
+ type Query {
48
+ b: String!
49
+ }
50
+ ` ,
51
+ serviceName : 'b' ,
52
+ serviceUrl : 'https://api.com/b' ,
53
+ expect : 'latest-composable' ,
54
+ } ) ;
55
+
56
+ const rawMessage = await cli . check ( {
57
+ sdl : /* GraphQL */ `
58
+ scalar Unused
59
+
60
+ scalar Used
61
+
62
+ directive @hasRole(role: Role!) on QUERY | MUTATION | FIELD_DEFINITION
63
+
64
+ directive @hasRoles(roles: [Role!]) on QUERY | MUTATION | FIELD_DEFINITION
65
+
66
+ enum Role {
67
+ admin
68
+ user
69
+ }
70
+
71
+ enum Permission {
72
+ read
73
+ write
74
+ create
75
+ delete
76
+ }
77
+
78
+ type Query {
79
+ userRole(roleID: Int!): UserRole! @hasRole(role: admin)
80
+ scalar: Used
81
+ }
82
+
83
+ type UserRole {
84
+ id: ID!
85
+ name: String!
86
+ }
87
+ ` ,
88
+ serviceName : 'c' ,
89
+ expect : 'rejected' ,
90
+ } ) ;
91
+ const message = stripAnsi ( rawMessage ) ;
92
+
93
+ expect ( message ) . toContain ( `Detected 2 errors` ) ;
94
+ expect ( message . split ( '\n' ) . slice ( 1 ) ) . toEqual ( [
95
+ '✖ Detected 5 errors' ,
96
+ '' ,
97
+ ' - Scalar type `Unused` is unreachable. (source: policy-no-unreachable-types)' ,
98
+ ' - Enum type `Permission` is unreachable. (source: policy-no-unreachable-types)' ,
99
+ '' ,
100
+ 'ℹ Detected 7 changes' ,
101
+ '' ,
102
+ ' Safe changes:' ,
103
+ ' - Type Permission was added' ,
104
+ ' - Type Role was added' ,
105
+ ' - Type Unused was added' ,
106
+ ' - Type Used was added' ,
107
+ ' - Type UserRole was added' ,
108
+ ' - Field scalar was added to object type Query' ,
109
+ ' - Field userRole was added to object type Query' ,
110
+ '' ,
111
+ 'View full report:' ,
112
+ expect . any ( String ) ,
113
+ '' ,
114
+ ] ) ;
115
+ } ) ;
116
+
20
117
it ( 'Federation project with policy with only warnings, should check only the part that was changed' , async ( ) => {
21
118
const { tokens, policy } = await prepareProject ( ProjectType . Federation ) ;
22
119
await policy . setOrganizationSchemaPolicy (
0 commit comments