-
-
Notifications
You must be signed in to change notification settings - Fork 266
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
Resolve alias field #211
Comments
This is my return [
'idUser' => [
'type' => Type::nonNull(Type::int()),
'description' => 'User identification, primary key'
],
'images' => [
'type' => GraphQL::paginate('ImageType'),
'description' => 'Images create by the user',
'args' => $pagination
],
] protected function resolveImagesField($root, $args)
{
$images = $root->images();
return $images->paginate($args['limit'], ['*'], 'page', $args['page']);
} |
Thanks, @albertcito. In my case is different. I want understand because the alias is not resolved automatically. BTW you are passing $pagination to args, to receive him in resolveImagesField($root, $args) method. What does $pagination do? And where i can find all attributes that can be passed to a field (like as: type, description, args, alias, ...others)? |
Please elaborate your issue or show an example |
Let's say i creating a Customer Type from a model that has a attribute called address_number. Then we would have something similar to this: <?php
class Subscriber extends Type
{
// ...
public function fields()
{
'addressNumber' => [
'type' => Type::int(),
'alias' => 'address_number'
]
}
} In that case, if I do not implement the resolveAddressNumberResolve() method, the address_number value will not be returned, although the field is being queried in the database. My question is: should not this / could happen automatically, since I am informing the alias? This ends up generating unnecessary code. Implementing this method would be interesting in cases such as the email field mentioned in the example of the repository itself, where the field needs to be returned in the low case. |
Same issue as #130 if i understand correctly your problem <?php
class Subscriber extends Type
{
// ...
public function fields()
{
'addressNumber' => [
'type' => Type::int(),
'alias' => 'address_number',
'resolve' => function ($root) { // As a workaround
return $root->address_number;
}
]
}
} |
@anolek exactly! My question is: because alias is not resolved automatically as mentioned by @rebing here? Follow a piece of his comment:
|
@zabaala As I mentioned in the other thread, you can look into it and find the problem in |
@zabaala I believe this was fixed with #283 , can you try the v1.22.0 release? |
After upgrading to v1.22.0, it is, indeed fixed @mfn |
I'll try it soon, @mfn. Thanks. |
Aliases work for me as well with v1.22.0. |
There has been now feedback from OP but given the other feedback and the PR I merged, I'm pretty sure this is fixed. If not, please simply create a new issue => thanks! |
Hi
I'm trying to create somes types and a case sound strange for me. When I try to create a field with a custom name, and I set the correct field name in alias, the aliased value field value is not returned.
The value is returned only if implement resolveCustomFieldResolve() method. It's correct?
Thanks.
The text was updated successfully, but these errors were encountered: