-
Notifications
You must be signed in to change notification settings - Fork 13
feat: add MAX_ITEMS_PER_QUERY #175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
| 'MAX_BATCH_MUTATION', | ||
| 'LOGGER_.+', | ||
| 'ROBOTS_TXT', | ||
| 'MAX_RELATIONAL_DEPTH', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not present in the rest of the code ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It already existed; it just wasn’t present here like all environment variables. Here’s an example of a call:
const maxRelationalDepth = Number(env['MAX_RELATIONAL_DEPTH']) > 2 ? Number(env['MAX_RELATIONAL_DEPTH']) : 2;
api/src/utils/sanitize-query.ts
Outdated
| let limit = sanitizeLimit(rawQuery['limit']); | ||
|
|
||
| if (typeof limit === 'number') { | ||
| const maxItemsPerQuery = Number(env['MAX_ITEMS_PER_QUERY']); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
env already has a functionality to format env value.
It uses either typeMap or a type prefix in the env variable.
Would it be possible to use this instead ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, I will look into that. I based myself on the existing practices on the following line:
const maxRelationalDepth = Number(env['MAX_RELATIONAL_DEPTH']) > 2 ? Number(env['MAX_RELATIONAL_DEPTH']) : 2;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to be automatically converted with:
if (
String(value).startsWith('0') === false &&
isNaN(value) === false &&
value.length > 0 &&
value <= Number.MAX_SAFE_INTEGER
) {
env[key] = Number(value);
continue;
}
It could be enforced by adding it in typeMap.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
then we can remove the Number(...) constructor ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's done
api/src/utils/sanitize-query.ts
Outdated
| if (typeof limit === 'number') { | ||
| const maxItemsPerQuery = Number(env['MAX_ITEMS_PER_QUERY']); | ||
|
|
||
| if (maxItemsPerQuery !== -1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maxItemsPerQuery !== -1 && limit === -1 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
api/src/utils/validate-query.ts
Outdated
| } | ||
|
|
||
| function validateLimit(limit: any) { | ||
| const maxItemsPerQuery = Number(env['MAX_ITEMS_PER_QUERY']) || 1000; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be manage by the getEnv and env definition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, moreover, I initialized it in defaults.
api/src/utils/validate-query.ts
Outdated
| function validateLimit(limit: any) { | ||
| const maxItemsPerQuery = Number(env['MAX_ITEMS_PER_QUERY']) || 1000; | ||
|
|
||
| if (limit !== -1 && maxItemsPerQuery !== -1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maxItemsPerQuery !== -1 is sufficient here ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, that was the initial test before adding the sanitize.
Change description
Type of change
Related issues
Checklists
Development
Security
Network
Code review