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
See below for a context and later I will describe result and expectation.
class FiltersFactory
{
/**
* @Factory
*/
public function createFilters(?string $param = null): Filters
{
$filters = new Filters();
if ($param) {
$filters->add('param', $param);
}
return $filters;
}
}
and now extended input
class FiltersDecorator
{
/**
* @Decorate(inputTypeName="FiltersInput")
*/
public function addExtraFilter(Filters $previous, ?int $param = null)
{
if ($param) {
$previous->add('param', $param);
}
return $previous;
}
}
Query
product(filters:{param:"hello"})
Expectation without FiltersDecorator
Works well because param is of type string, so it's gonna be set through Filters factory
Result
The same
Expectation with FiltersDecorator
GraphQL throws an exception because param must by of type Int!
Result
The same
Fixed query
product(filters:{param:5})
Expectation
Works well because now type is int and param will be set through FiltersDecorat
Result
Internals throw exception String cannot represent a non string value: 5
Reporting this as a bug, but maybe overridding should not be possible in the first place, otherwise casting to old type should not happen. If I changed to int and sent int, then it's not string anymore.
The text was updated successfully, but these errors were encountered:
@golaod I'm not entirely sure what you're looking to accomplish at the end of the day, but I'm doubtful that the Decorate annotation is best solution. Nonetheless, I'm not sure, at least according to the docs, that it supports overriding an existing field. I've never used the Decorate annotation, and would do my best to keep it that way.
Why not use another field here if it's of a different type? Additionally, it's highly recommended in GraphQL to create more input types for different scenarios, as opposed to trying to do more with a single input type.
See below for a context and later I will describe result and expectation.
and now extended input
Query
Expectation without FiltersDecorator
Works well because param is of type string, so it's gonna be set through Filters factory
Result
The same
Expectation with FiltersDecorator
GraphQL throws an exception because param must by of type Int!
Result
The same
Fixed query
Expectation
Works well because now type is int and param will be set through FiltersDecorat
Result
Internals throw exception
String cannot represent a non string value: 5
Reporting this as a bug, but maybe overridding should not be possible in the first place, otherwise casting to old type should not happen. If I changed to int and sent int, then it's not string anymore.
The text was updated successfully, but these errors were encountered: