You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
How is it possible to validate the subquery args parameters?
Example:
class UserType extends GraphQLType
{
// ...
public function fields(): array
{
return [
// ...
// Relation
'posts' => [
'type' => Type::listOf(GraphQL::type('post')),
'description' => 'A list of posts written by the user',
'args' => [
'date_from' => [
'type' => Type::string(),
'rules' => [ // this parameter has no effect
'filled',
'date'
]
],
],
'rules' => [ // this parameter has no effect
'date_from' => [
'filled',
'date'
]
],
// $args are the local arguments passed to the relation
// $query is the relation builder object
// $ctx is the GraphQL context (can be customized by overriding `\Rebing\GraphQL\GraphQLController::queryContext`
'query' => function(array $args, $query, $ctx) {
return $query->where('posts.created_at', '>', $args['date_from']);
}
]
];
}
}
Current solution (verbose):
class UserType extends GraphQLType
{
// ...
public function fields(): array
{
return [
// ...
// Relation
'posts' => [
'type' => Type::listOf(GraphQL::type('post')),
'description' => 'A list of posts written by the user',
'args' => [
'date_from' => [
'type' => Type::string(),
],
],
// $args are the local arguments passed to the relation
// $query is the relation builder object
// $ctx is the GraphQL context (can be customized by overriding `\Rebing\GraphQL\GraphQLController::queryContext`
'query' => function(array $args, $query, $ctx) {
$validator = \Illuminate\Support\Facades\Validator::make($args, [
'date_from' => [
'filled',
'date'
]
]);
if ($validator->fails()) throw new \Rebing\GraphQL\Error\ValidationError('validation', $validator);
return $query->where('posts.created_at', '>', $args['date_from']);
}
]
];
}
}
There is a better way?
Thanks
The text was updated successfully, but these errors were encountered:
I have the same problem here with the latest version when trying to use these nested validations with a PaginationType query, as a workaround I've extended validateFieldArguments in the query like this:
public function validateFieldArguments(array $fieldsAndArgumentsSelection): void
{
$argsRules = (new RulesInFields(GraphQL::type('mytype'), $fieldsAndArgumentsSelection['data']['fields']))->get();
if (count($argsRules)) {
$validator = $this->getValidator($fieldsAndArgumentsSelection['data']['fields'], $argsRules);
if ($validator->fails()) {
throw new ValidationError('validation', $validator);
}
}
}
I'm not sure if we should take that into account in RulesInFields or if it the PaginationType should be responsible for dealing with it
Versions:
Question:
How is it possible to validate the subquery args parameters?
Example:
Current solution (verbose):
There is a better way?
Thanks
The text was updated successfully, but these errors were encountered: