@@ -161,7 +161,7 @@ const typeWeights: TypeWeightObject = {
161161 } ,
162162} ;
163163
164- xdescribe ( 'Test getQueryTypeComplexity function' , ( ) => {
164+ describe ( 'Test getQueryTypeComplexity function' , ( ) => {
165165 let query = '' ;
166166 describe ( 'Calculates the correct type complexity for queries' , ( ) => {
167167 beforeEach ( ( ) => {
@@ -244,20 +244,12 @@ xdescribe('Test getQueryTypeComplexity function', () => {
244244 } ) ;
245245
246246 /**
247+ * TODO: handle lists of unknown size
247248 *
248- * With type complexity analysis, all objects returned count towards the total complexity.
249- * For example, the cost of querying for 5 friends is 5. I do not have any clue how we would know
250- * to look for the argument 'first' to know, before running the query, how many objects are expected to be returned.
249+ * Figure out the implementation before tests
251250 *
252- * Anouther example, if we queried the 'Search' type with some string argument, the returned number of objects
253- * could be very large. Our algorithm will need to know what limit is set for the returned data (limit 100 search results
254- * for example) and then account for that response to caculate the complexity. That information is in the resolvers. We
255- * have no access to the resolvers.
256- *
257- * Some user configuration will be needed unless someone has bright ideas.
258251 */
259- // ? type weigts are variable, not sure how to calculate this.
260- test ( 'with lists' , ( ) => {
252+ xtest ( 'with lists of unknown size' , ( ) => {
261253 query = `
262254 Query {
263255 human(id: 1) {
@@ -267,9 +259,12 @@ xdescribe('Test getQueryTypeComplexity function', () => {
267259 }
268260 }
269261 }` ;
270- expect ( getQueryTypeComplxity ( query , typeWeights ) ) . toBe ( 7 ) ; // 1 Query + 1 human/character + 5 friends/character
262+ expect ( getQueryTypeComplxity ( query , typeWeights ) ) . toBe ( false ) ; // ?
263+ } ) ;
264+
265+ test ( 'with lists detrmined by arguments' , ( ) => {
271266 query = `Query {reviews(episode: EMPIRE, first: 3) { stars, commentary } }` ;
272- expect ( getQueryTypeComplxity ( query , typeWeights ) ) . toBe ( 4 ) ; // 1 Query + 3 reviews
267+ expect ( getQueryTypeComplxity ( query , typeWeights ) ) . toBe ( false ) ; // 1 Query + 3 reviews
273268 } ) ;
274269
275270 test ( 'with nested lists' , ( ) => {
@@ -308,17 +303,14 @@ xdescribe('Test getQueryTypeComplexity function', () => {
308303
309304 // todo: directives @skip , @include and custom directives
310305
311- // todo: error handling
312- // look into error handling for graphql. The only error I forsee is if the query is invalid in
313- // which case we want to pass the query along to the graphQL server to handle.
314- // What would that look like here? I think we should throw ar error from this function.
306+ // todo: expand on error handling
315307 test ( 'Throws an error if for a bad query' , ( ) => {
316308 query = `Query { hello { hi } }` ; // type doesn't exist
317- expect ( getQueryTypeComplxity ( query , typeWeights ) ) . toThrow ( 'Error' ) ;
309+ expect ( ( ) => getQueryTypeComplxity ( query , typeWeights ) ) . toThrow ( 'Error' ) ;
318310 query = `Query { hero(episode: EMPIRE){ starship } }` ; // field doesn't exist
319- expect ( getQueryTypeComplxity ( query , typeWeights ) ) . toThrow ( 'Error' ) ;
311+ expect ( ( ) => getQueryTypeComplxity ( query , typeWeights ) ) . toThrow ( 'Error' ) ;
320312 query = `Query { hero(episode: EMPIRE) { id, name }` ; // missing a closing bracket
321- expect ( getQueryTypeComplxity ( query , typeWeights ) ) . toThrow ( 'Error' ) ;
313+ expect ( ( ) => getQueryTypeComplxity ( query , typeWeights ) ) . toThrow ( 'Error' ) ;
322314 } ) ;
323315 } ) ;
324316
0 commit comments