Skip to content

Commit 8efe822

Browse files
authored
updated readme
1 parent 77d7db5 commit 8efe822

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

README.md

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ app.use(
7272
- `options: RedisOptions` | [ioredis configuration options](https://github.com/luin/ioredis) | defaults to standard ioredis connection options (`localhost:6379`)
7373
- `keyExpiry: number` (ms) | custom expiry of keys in redis cache | defaults to 24 hours
7474

75-
- `typeWeights: TypeWeightObject`
75+
- <a name="typeWeights"></a>`typeWeights: TypeWeightObject`
7676

7777
- `mutation: number` | assigned weight to mutations | defaults to 10
7878
- `query: number` | assigned weight of a query | defaults to 1
@@ -81,7 +81,7 @@ app.use(
8181

8282
- `depthLimit: number` | throttle queies by the depth of the nested stucture | defaults to `Infinity` (ie. no limit)
8383
- `enforceBoundedLists: boolean` | if true, an error will be thrown if any lists types are not bound by slicing arguments [`first`, `last`, `limit`] or directives | defaults to `false`
84-
- `dark: boolean` | if true, the package will calculate complexity, depth and tokens but not throttle any queries. Use this to dark launch the package and monitor what would happen if rate limiting was added to yaur application
84+
- `dark: boolean` | if true, the package will calculate complexity, depth and tokens but not throttle any queries. Use this to dark launch the package and monitor the rate limiter's impact without limiting user requests.
8585

8686
All configuration options
8787

@@ -113,27 +113,27 @@ app.use(
113113

114114
## <a name="lists"></a> Notes on Lists
115115

116-
The complexity for list types can be set in the schema with the use of directives, or in the query by the varibales passed to the field as slicing arguments.
116+
For queries that return a list, the complexity can be determined with schema directives, or by providing a slicing argument to the query (`first`, `last`, `limit).
117117

118-
1. Slicing arguments: lists must be bounded by one integer slicing argument in order to calculate the comlexity for the field. This package supports the slicing arguments `first`, `last` and `limit`. The complexity of the list will be the value passed as the argument to the field.
118+
1. Slicing arguments: lists must be bounded by one integer slicing argument in order to calculate the complexity for the field. This package supports the slicing arguments `first`, `last` and `limit`. The complexity of the list will be the value passed as the argument to the field.
119119

120120
2. Directives: ... TODO ...
121121

122122

123123
## <a name="how-it-works"></a> How It Works
124124

125-
Rate-limiting is done by IP address.
125+
Requests are rate-limited based on the IP address associated with the request.
126126

127-
On server start, the GraphQL (GQL) schema is parsed to build an object that maps GQL types/fields to values corresponding to the weights assigned to each GQL type/field. This object is used internally to cross reference the fields queried by the user with the weight to apply that field when totaling the overall complexity of the query.
127+
On server start, the GraphQL (GQL) schema is parsed to build an object that maps GQL types/fields to their corresponding weights. Type weights can be provided during <a href="typeWeights">initial configuration</a>. When a request is received, this object is used to cross reference the fields queried by the user and compute the complexity of each field. The total complexity of the request is the sum of these values.
128128

129-
For each request, the query is parsed and traversed to total the overall complexity of the query based on the type/field weights configured on setup. This is done statically (before any resolvers are called) to estimate the upper bound of response size of the request - a proxy for the work done by the server to build the response. The total complexity is then used to allow/block the request based on popular rate-limiting algorithms.
129+
Complexity is determined, statically (before any resolvers are called) to estimate the upper bound of the response size - a proxy for the work done by the server to build the response. The total complexity is then used to allow/block the request based on popular rate-limiting algorithms.
130130

131-
If a user sends two request simustaneously, the trailing request will wait for the first one to complete any asyncronous work before being processed.
131+
Requests for each user are processed sequentially by the rate limiter.
132132

133133
Example (with default weights):
134134

135135
```javascript
136-
query { // 1
136+
query { // 1 (complexity)
137137
hero (episode: EMPIRE) { // 1
138138
name // 0
139139
id // 0
@@ -152,13 +152,13 @@ query { // 1
152152

153153
## <a name="response"></a> Response
154154

155-
1. Blocked Requests: blocked requests recieve a response with,
155+
1. <b>Blocked Requests</b>: blocked requests recieve a response with,
156156

157-
- status of `429` for ` Too Many Requests`
157+
- status of `429` for `Too Many Requests`
158158
- `Retry-After` header with a value of the time to wait in seconds before the request would be approved (`Infinity` if the complexity is greater than rate-limiting capacity).
159-
- A JSON response with the `tokens` available, `complexity` of the query, `depth` of the query, `success` of the query set to `false`, and the `timestamp` of the request in ms
159+
- A JSON response with the `tokens` available, `complexity` of the query, `depth` of the query, `success` of the query set to `false`, and the UNIX `timestamp` of the request
160160

161-
2. Successful Requests: successful request are passed onto the next function in the middleware chain with the following properties saved to `res.locals`
161+
2. <b>Successful Requests</b>: successful requests are passed onto the next function in the middleware chain with the following properties saved to `res.locals`
162162

163163
```javascript
164164
{
@@ -179,12 +179,13 @@ query { // 1
179179

180180
## <a name="future-development"></a> Future Development
181181

182-
- the ability to use this package with other caching technologies or libraries
183-
- implement "resolve complexity analysis" for queries
184-
- implement leaky bucket algorithm for rate-limiting
185-
- experiment with performance improvements
182+
- Ability to use this package with other caching technologies or libraries
183+
- Implement "resolve complexity analysis" for queries
184+
- Implement leaky bucket algorithm for rate-limiting
185+
- Experiment with performance improvements
186186
- caching optimization
187-
- ensure connection pagination conventions can be accuratly acconuted for in comprlexity analysis
187+
- Ensure connection pagination conventions can be accuratly acconuted for in complexity analysis
188+
- Ability to use middleware with other server frameworks
188189

189190
## <a name="contributions"></a> Contributions
190191

0 commit comments

Comments
 (0)