Skip to content

allow validation rules to be passed during schema execution #82

Closed
@aryaniyaps

Description

@aryaniyaps

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions