drupal-graphql / drupal-graphql/graphql

How to expose reverse entity references?

Open
#945 0 comments 2 reactions 0 assignees View on GitHub
4.x documentation question
Dominant language
PHP
Stars
287
Forks
198
PR merge metrics
No merged PRs in 30d

Description

Since Drupal 8 doesn't support bidirectional relationship, we need to query manually the reverse entity.

Let's say we have 2 entities with a many to many relationship:

Screenshot 2019-11-13 at 19 58 19

We can add a field resolver to get all books from an author, like explained in [the doc](https://drupal-graphql.gitbook.io/graphql/v/8.x-4.x/queries/references#adding-resolvers):

```
$registry->addFieldResolver('Author', 'books',
$builder->compose(
$builder->produce('entity_reference')
->map('entity', $builder->fromParent())
->map('field', $builder->fromValue('field_books'))
)
);
```

But how can we get all authors from a book?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.