Skip to content
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

Make all limits of the of the complexity to be configurable via the CLI #2318

Closed
xgreenx opened this issue Oct 8, 2024 · 4 comments · Fixed by #2335
Closed

Make all limits of the of the complexity to be configurable via the CLI #2318

xgreenx opened this issue Oct 8, 2024 · 4 comments · Fixed by #2335
Assignees

Comments

@xgreenx
Copy link
Collaborator

xgreenx commented Oct 8, 2024

image
@netrome
Copy link
Contributor

netrome commented Oct 10, 2024

Input from grooming: Just adding all of these as CLI args with the given defaults seems like a good starting point.

@netrome netrome assigned netrome and unassigned netrome Oct 10, 2024
@acerone85
Copy link
Contributor

Started having a look at this. It does not look like we can easily change the #[graphql(complexity = "QUERY_COSTS.query_name")] field to use values computed at runtime.
See for example

#[graphql(complexity = "QUERY_COSTS.balance_query")]
.

In particular, async_graphql checks the complexity in the validation phase, whereas the code of the query corresponds to what is executed in the execution phase. So, even if you added the query complexity costs in the execution context, it won't be possible to compare these values against the actual query complexity.

A better approach seems to be using async_graphql extensions. In particular, it looks that the analyzer extension can be tweaked to limit query complexity with values specified at runtime. Note that extensions are run against all graphQL requests, not only queries.

Pinging @xgreenx to validate the approach.

@netrome
Copy link
Contributor

netrome commented Oct 11, 2024

Started having a look at this. It does not look like we can easily change the #[graphql(complexity = "QUERY_COSTS.query_name")] field to use values computed at runtime. See for example

#[graphql(complexity = "QUERY_COSTS.balance_query")]

.

In particular, async_graphql checks the complexity in the validation phase, whereas the code of the query corresponds to what is executed in the execution phase. So, even if you added the query complexity costs in the execution context, it won't be possible to compare these values against the actual query complexity.

A better approach seems to be using async_graphql extensions. In particular, it looks that the analyzer extension can be tweaked to limit query complexity with values specified at runtime. Note that extensions are run against all graphQL requests, not only queries.

Pinging @xgreenx to validate the approach.

Actually the complexity expression is evaluated at runtime so if we can do

#[graphql(complexity = "my_complexity_function()")] 

Where the function could have access to some lazy static value that we initialize once the system starts up.

Though extensions may be a better way to go about it.

@netrome
Copy link
Contributor

netrome commented Oct 11, 2024

If we do write an extension here, we need to be careful not to hit the same race condition as in #2330 (comment). We could probably use the same solution, but perhaps it's simpler to just use a OnceLock that we write to when we parse the configuration. I don't think that would be too complex, and the overhead of this approach should be should be negligible.

@netrome netrome linked a pull request Oct 11, 2024 that will close this issue
3 tasks
xgreenx added a commit that referenced this issue Oct 14, 2024
## Linked Issues/PRs
- Closes #2318 

## Description
This PR adds CLI options to configure graphql query costs dynamically.

## Checklist
- [x] Breaking changes are clearly marked as such in the PR description
and changelog
- [x] New behavior is reflected in tests

### Before requesting review
- [x] I have reviewed the code myself

### After merging, notify other teams

[Add or remove entries as needed]

- [ ] [Rust SDK](https://github.com/FuelLabs/fuels-rs/)
- [ ] [Platform
documentation](https://github.com/FuelLabs/devrel-requests/issues/new?assignees=&labels=new+request&projects=&template=NEW-REQUEST.yml&title=%5BRequest%5D%3A+)
(for out-of-organization contributors, the person merging the PR will do
this)

---------

Co-authored-by: acerone85 <andrea.cerone@gmail.com>
Co-authored-by: Green Baneling <XgreenX9999@gmail.com>
@netrome netrome closed this as completed Oct 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants