Skip to content

Commit e5c194c

Browse files
committed
broke the lists test into two, one for listss with arguments and the other without
1 parent c435c93 commit e5c194c

File tree

2 files changed

+25
-24
lines changed

2 files changed

+25
-24
lines changed

src/rateLimiters/tokenBucket.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ import { RedisClientType } from 'redis';
99
* 4. Otherwise, disallow the request and do not update the token total.
1010
*/
1111
class TokenBucket implements RateLimiter {
12-
capacity: number;
12+
private capacity: number;
1313

14-
refillRate: number;
14+
private refillRate: number;
1515

16-
client: RedisClientType;
16+
private client: RedisClientType;
1717

1818
/**
1919
* Create a new instance of a TokenBucket rate limiter that can be connected to any database store
@@ -29,6 +29,15 @@ class TokenBucket implements RateLimiter {
2929
throw Error('TokenBucket refillRate and capacity must be positive');
3030
}
3131

32+
/**
33+
*
34+
*
35+
* @param {string} uuid - unique identifer used to throttle requests
36+
* @param {number} timestamp - time the request was recieved
37+
* @param {number} [tokens=1] - complexity of the query for throttling requests
38+
* @return {*} {Promise<RateLimiterResponse>}
39+
* @memberof TokenBucket
40+
*/
3241
async processRequest(
3342
uuid: string,
3443
timestamp: number,

test/analysis/typeComplexityAnalysis.test.ts

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)