Skip to content

Commit 2f838b8

Browse files
authored
Merge pull request #14 from oslabs-beta/em/typeWeightsTest
Created function signature and testsuite for the buildTypeWeightsFromSchemaObject function
2 parents 350a000 + 22bf283 commit 2f838b8

File tree

18 files changed

+10267
-2030
lines changed

18 files changed

+10267
-2030
lines changed

.babelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": [["@babel/preset-env", { "targets": { "node": "current" } }], "@babel/preset-typescript"],
3+
}

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

.eslintrc.json

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,28 @@
44
"commonjs": true,
55
"es2021": true
66
},
7-
"extends": ["eslint:recommended", "airbnb-base"],
7+
"extends": [
8+
"eslint:recommended",
9+
"airbnb-base",
10+
"airbnb-typescript/base",
11+
"plugin:@typescript-eslint/recommended",
12+
"plugin:import/typescript",
13+
"prettier"
14+
],
815
"parser": "@typescript-eslint/parser",
916
"parserOptions": {
10-
"ecmaVersion": "latest"
17+
"ecmaVersion": "latest",
18+
"project": "./tsconfig.eslint.json"
1119
},
12-
"plugins": ["@typescript-eslint"],
20+
"plugins": ["import"],
1321
"rules": {
1422
"indent": [
1523
"warn",
16-
2,
24+
4,
1725
{
18-
"SwitchCase": 1
26+
"SwitchCase": 2
1927
}
2028
]
21-
}
29+
},
30+
"ignorePatterns": ["jest.config.js"]
2231
}

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ branches:
66
- dev
77
script:
88
- 'npm run lint'
9-
# - "npm run test"
9+
- 'npm run test'

.vscode/settings.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"folders": [],
3+
"settings": {},
4+
"editor.codeActionsOnSave": {
5+
"source.fixAll.eslint": true
6+
},
7+
"editor.formatOnSave": true,
8+
}

jest.config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
2+
module.exports = {
3+
roots: ['./test'],
4+
preset: 'ts-jest',
5+
testEnvironment: 'node',
6+
moduleFileExtensions: ['js', 'ts'],
7+
};

package-lock.json

Lines changed: 9757 additions & 2016 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "A GraphQL rate limiting library using query complexity analysis.",
55
"main": "index.js",
66
"scripts": {
7-
"test": "echo \"Error: no test specified\" && exit 1",
7+
"test": "jest --passWithNoTests",
88
"lint": "eslint src",
99
"lint:fix": "eslint --fix src",
1010
"prettier": "prettier --write .",
@@ -22,17 +22,30 @@
2222
},
2323
"homepage": "https://github.com/oslabs-beta/graph-beaver#readme",
2424
"devDependencies": {
25-
"@typescript-eslint/eslint-plugin": "^5.23.0",
26-
"@typescript-eslint/parser": "^5.23.0",
25+
"@babel/core": "^7.17.12",
26+
"@babel/preset-env": "^7.17.12",
27+
"@babel/preset-typescript": "^7.17.12",
28+
"@types/jest": "^27.5.1",
29+
"@typescript-eslint/eslint-plugin": "^5.24.0",
30+
"@typescript-eslint/parser": "^5.24.0",
31+
"babel-jest": "^28.1.0",
2732
"eslint": "^8.15.0",
2833
"eslint-config-airbnb-base": "^15.0.0",
34+
"eslint-config-airbnb-typescript": "^17.0.0",
35+
"eslint-config-prettier": "^8.5.0",
2936
"eslint-plugin-import": "^2.26.0",
3037
"husky": "^8.0.1",
38+
"jest": "^28.1.0",
3139
"lint-staged": "^12.4.1",
32-
"prettier": "2.6.2"
40+
"prettier": "2.6.2",
41+
"ts-jest": "^28.0.2",
42+
"typescript": "^4.6.4"
3343
},
3444
"lint-staged": {
3545
"*.{js, ts}": "eslint --cache --fix",
3646
"*.{js,ts,css,md}": "prettier --write --ignore-unknown"
47+
},
48+
"dependencies": {
49+
"graphql": "^16.5.0"
3750
}
3851
}

src/@types/buildTypeWeights.d.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
interface Fields {
2+
[index: string]: number;
3+
}
4+
5+
interface Type {
6+
weight: number;
7+
fields: Fields;
8+
}
9+
10+
interface TypeWeightObject {
11+
[index: string]: Type;
12+
}
13+
14+
interface TypeWeightConfig {
15+
mutation?: number;
16+
query?: number;
17+
object?: number;
18+
scalar?: number;
19+
connection?: number;
20+
}

src/@types/rateLimit.d.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
interface RateLimiter {
2+
/**
3+
* Checks if a request is allowed under the given conditions and withdraws the specified number of tokens
4+
* @param uuid Unique identifier for the user associated with the request
5+
* @param tokens Number of tokens being used in this request. Optional
6+
* @returns true if the request is allowed
7+
*/
8+
processRequest: (uuid: string, tokens?: number) => boolean;
9+
/**
10+
* Connects the RateLimiter instance to a db to cache current token usage for connected users
11+
* @param uri database connection string
12+
*/
13+
connect: (uri: string) => void;
14+
}

0 commit comments

Comments
 (0)