drupal-graphql / drupal-graphql/graphql
v4: typeResolvers aren't working
- Dominant language
- PHP
- Stars
- 287
- Forks
- 198
- PR merge metrics
- No merged PRs in 30d
Description
So I'm trying to get Paragraphs using GraphQL so I made a Paragraph interface and a typeresolver:
```graphql
interface Paragraph {
id: Int!
}
type Service {
id: Int!
title: String!
description: String!
introduction: String!
icon: String!
path: String!
solution: Solution
content: [Paragraph]
}
type WysiwygParagraph implements Paragraph {
id: Int!
}
```
```php
$registry->addFieldResolver('Service', 'content',
$builder->produce('entity_reference_revisions')
->map('entity', $builder->fromParent())
->map('field', $builder->fromValue('field_content')
));
$registry->addTypeResolver('Paragraph', function ($value) {
switch ($value->bundle()) {
case 'wysiwyg': return 'WysiwygParagraph';
}
throw new Error('Could not resolve Paragraph type.');
});
$registry->addFieldResolver('WysiwygParagraph', 'id',
$builder->produce('entity_id')
->map('entity', $builder->fromParent()
));
```
I followed the documentation exactly, checked it soo many times, but it keeps throwing:
```
"Abstract type Paragraph must resolve to an Object type at runtime for field Service.content with value \"instance of Drupal\\paragraphs\\Entity\\Paragraph\", received \"null\". Either the Paragraph type should provide a \"resolveType\" function or each possible type should provide an \"isTypeOf\" function."
```
The weird thing is, I can't find any code that handles the typeResolvers. There are only added to the ResolverRegistry but the function resolveType() is never executed somewhere, and I can't find it in the module's code.
Using logs I can also say that the code never reaches the resolver function
What am I doing wrong? Can someone help me?
- Perry
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.