@@ -87,6 +87,68 @@ describe('costLimitPlugin', () => {
87
87
] ) ;
88
88
} ) ;
89
89
90
+ it ( 'should limit cost for query named `__schema`' , async ( ) => {
91
+ const testkit = createTestkit (
92
+ [
93
+ costLimitPlugin ( {
94
+ maxCost : 10 ,
95
+ objectCost : 4 ,
96
+ scalarCost : 2 ,
97
+ depthCostFactor : 2 ,
98
+ ignoreIntrospection : true ,
99
+ } ) ,
100
+ ] ,
101
+ schema ,
102
+ ) ;
103
+ const result = await testkit . execute ( `
104
+ query __schema {
105
+ books {
106
+ title
107
+ author
108
+ }
109
+ }
110
+ ` ) ;
111
+
112
+ assertSingleExecutionValue ( result ) ;
113
+ expect ( result . errors ) . toBeDefined ( ) ;
114
+ expect ( result . errors ?. map ( ( error ) => error . message ) ) . toEqual ( [
115
+ 'Syntax Error: Query Cost limit of 10 exceeded, found 12.' ,
116
+ ] ) ;
117
+ } ) ;
118
+
119
+ it ( 'should limit cost for fragment named `__schema`' , async ( ) => {
120
+ const testkit = createTestkit (
121
+ [
122
+ costLimitPlugin ( {
123
+ maxCost : 10 ,
124
+ objectCost : 4 ,
125
+ scalarCost : 2 ,
126
+ depthCostFactor : 2 ,
127
+ ignoreIntrospection : true ,
128
+ } ) ,
129
+ ] ,
130
+ schema ,
131
+ ) ;
132
+ const result = await testkit . execute ( `
133
+ query {
134
+ ...__schema
135
+ }
136
+
137
+ fragment __schema on Query {
138
+ books {
139
+ title
140
+ author
141
+ }
142
+ }
143
+ ` ) ;
144
+
145
+ assertSingleExecutionValue ( result ) ;
146
+ expect ( result . errors ) . toBeDefined ( ) ;
147
+ expect ( result . errors ?. map ( ( error ) => error . message ) ) . toEqual ( [
148
+ 'Syntax Error: Query Cost limit of 10 exceeded, found 58.' ,
149
+ ] ) ;
150
+ } ) ;
151
+
90
152
it ( 'should allow introspection' , async ( ) => {
91
153
const testkit = createTestkit (
92
154
[
@@ -100,6 +162,7 @@ describe('costLimitPlugin', () => {
100
162
] ,
101
163
schema ,
102
164
) ;
165
+ const x = getIntrospectionQuery ( ) ;
103
166
const result = await testkit . execute ( getIntrospectionQuery ( ) ) ;
104
167
105
168
assertSingleExecutionValue ( result ) ;
0 commit comments