drupal-graphql / drupal-graphql/graphql
Field resolver needs configuration entity field value
- Dominant language
- PHP
- Stars
- 287
- Forks
- 198
- PR merge metrics
- No merged PRs in 30d
Description
I need to create a field resolver that loads a content entity, where the entity id is stored in a parent configuration entity. This is for the drupal.org/project/outline module, but is a similar situation to the taxonomy module, where the taxonomy vocabulary is a configuration entity that has child content entities which are taxonomy terms.
Below is the schema, note that the Outline type has a field ```rootEntry```. In order to load the root entry field, the Outline configuration entity setting for 'root_entry_id' must be somehow referenced by the data producer to get the entity id. I tried the "field:" syntax I had noticed used for content entity fields but that did not work, the schema class code is also below. All of this code is checked into drupal.org repo at https://git.drupalcode.org/project/outline/-/tree/8.x-1.x/modules/outline_graphql.
```
schema {
query: Query
}
type Query {
entry(eid: Int!): Entry
outline(oid: String!): Outline
outlines(
offset: Int = 0
limit: Int = 100
): OutlineConnection!
}
type Entry {
eid: Int!
children: [Entry!]
content: String
name: String!
}
type Outline {
oid: String!
name: String!
rootEntry: Entry!
}
type OutlineConnection {
outlines: [Outline!]
total: Int!
}
```
Here is the field resolver from schema class:
```
$registry->addFieldResolver('Outline', 'rootEntry',
$builder->compose(
$builder->produce('field:root_entry_id')
->map('entity', $builder->fromParent()),
$builder->produce('entity_load')
->map('type', $builder->fromValue('outline_entry'))
->map('id', $builder->fromParent())
));
```
Thanks for you help!
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.