Skip to content

allow validation rules to be passed during schema execution #82

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

Closed
aryaniyaps opened this issue Aug 9, 2021 · 0 comments · Fixed by #83
Closed

allow validation rules to be passed during schema execution #82

aryaniyaps opened this issue Aug 9, 2021 · 0 comments · Fixed by #83

Comments

@aryaniyaps
Copy link
Contributor

aryaniyaps commented Aug 9, 2021

validation rules are the recommended way to implement things like depth limit validators and other sorts of protectors.
When inspecting the source code, I found out that validation_rules aren't passed as an argument during schema execution. It would be nice if this could be fixed so that we could implement our own validation rules.

execution_results, all_params = run_http_query(
self.schema,
request_method,
data,
query_data=request.args,
batch_enabled=self.batch,
catch=catch,
# Execute options
root_value=self.get_root_value(),
context_value=self.get_context(),
middleware=self.get_middleware(),
)

over here, the http query is run via the run_http_query function.
This method also takes other execution options, as shown below.

def run_http_query(
schema: GraphQLSchema,
request_method: str,
data: Union[Dict, List[Dict]],
query_data: Optional[Dict] = None,
batch_enabled: bool = False,
catch: bool = False,
run_sync: bool = True,
**execute_options,
) -> GraphQLResponse:

Inside the run_http_query method, this function is called.

get_response(
schema, params, catch_exc, allow_only_query, run_sync, **execute_options
)

this function, get_response takes another execution option, validation_rules.
This is not being passed anywhere, and always remains None.

def get_response(
schema: GraphQLSchema,
params: GraphQLParams,
catch_exc: Type[BaseException],
allow_only_query: bool = False,
run_sync: bool = True,
validation_rules: Optional[Collection[Type[ASTValidationRule]]] = None,
max_errors: Optional[int] = None,
**kwargs,
) -> Optional[AwaitableOrValue[ExecutionResult]]:

I will send a PR ASAP!

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.

1 participant