-
-
Notifications
You must be signed in to change notification settings - Fork 438
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
Correctly handle leaf inputs that were cast to PHP native enum instances #2209
Comments
How did you define your enum in the schema - did you implement a conversion to native enums akin to https://lighthouse-php.com/master/the-basics/types.html#enum? If not, the values would just be the - in your case uppercase - string equivalents of the keys (e.g. In case the values are converted to enum instances, the default implementation of |
@spawnia my bad, I use the feature from php-graphql master branch causing this issue. the feature is not in release yet, but I think its good for you guys to acknowledge first https://webonyx.github.io/graphql-php/type-definitions/enums/ what I put in composer.json "webonyx": "dev-master as 14.11" |
I would like to keep this issue open, as it is a problem that is generally present with leaf values that are cast into non-primitive values. |
i found out the enum BlogPostType {
ARTICLE
KNOWLEDGE_BASE
}
query {
posts(type: BlogPostType! @eq): [Post!]! @paginate @cache(maxAge: 300)
}
My workaround solution is simple also <?php
namespace App\GraphQL\Cache;
use Illuminate\Contracts\Auth\Authenticatable;
use Nuwave\Lighthouse\Cache\CacheKeyAndTagsGenerator as BaseGenerator;
use UnitEnum;
class CacheKeyAndTagsGenerator extends BaseGenerator
{
public function key(?Authenticatable $user, bool $isPrivate, string $parentName, $id, string $fieldName, array $args): string
{
$args = array_map(fn($v) => $v instanceof UnitEnum ? $v->name : $v, $args);
return parent::key($user, $isPrivate, $parentName, $id, $fieldName, $args);
}
} // AppServiceProvider
$this->app->bind(CacheKeyAndTags::class, fn() => new \App\GraphQL\Cache\CacheKeyAndTagsGenerator()); p/s: if the parameter is an object, the person who wrote the code just need to implement |
Could implementing |
no, php enum does not allow |
Describe the bug
Enum passed to validator resulting some dependant rules not working, for example:
required_if
at the end, the
ItemType
enum will passed to theValidator::validateRequiredIf
function and it will compare it with a string, which is alwaysfalse
see Laravel's ValidatesAttributes.php line 1589
Expected behavior/Solution
Probably convert all enum into its value/name before passing it to validator, but not sure any efficient way to do it or not.
Steps to reproduce
See the explanation above
Lighthouse Version
v5.61.0
-- Update --
Some workaround solution
The text was updated successfully, but these errors were encountered: