drupal-graphql / drupal-graphql/graphql
How to load multiple images
- Dominant language
- PHP
- Stars
- 287
- Forks
- 198
- PR merge metrics
- No merged PRs in 30d
Description
Hi, I'm struggeling a bit with loading multiple images from a custom type
My schema should be the following:
```
type Image {
id: Int!,
alt: String
url: String!
}
type Images {
id: Int!
year: Int
title: String!
images: [Image]
}
```
The resolvers look like this:
```
$registry->addFieldResolver('Images', 'images',
$builder->produce('entity_reference')
->map('entity', $builder->fromParent())
->map('field', $builder->fromValue('field_images'))
);
$registry->addFieldResolver('Image', 'url',
$builder->compose(
$builder->produce('image_derivative')
->map('style', $builder->fromValue('large'))
->map('entity', $builder->fromParent()),
$builder->callback(function($parent){
return $parent['url'];
})
)
);
```
This is working for the URL, but to resolve the `alt` field, I don't have access to the alt-field anymore, because the resolver for the field `images` resolves to a `Drupal\file\Entity\File`.
I think I have a mistake in my approach, how could I solve this to get the image url AND the alt text?
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.