Skip to content

Commit a1c6bb6

Browse files
rthideawayklausi
authored andcommitted
fix(EntityDefinition): Fix incorrect context type for "field_types" (drupal-graphql#991)
1 parent 1c6e420 commit a1c6bb6

2 files changed

Lines changed: 7 additions & 8 deletions

File tree

src/Plugin/GraphQL/DataProducer/EntityDefinition/EntityDefinition.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
* label = @Translation("Bundle"),
2525
* required = FALSE
2626
* ),
27-
* "field_types" = @ContextDefinition("FieldTypes",
28-
* label = @Translation("Field types"),
27+
* "field_types" = @ContextDefinition("string",
28+
* label = @Translation("Field types (ALL, BASE_FIELDS, FIELD_CONFIG)"),
2929
* default = "ALL",
3030
* required = FALSE
3131
* )

src/Plugin/GraphQL/DataProducer/EntityDefinition/Fields.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
* label = @Translation("Bundle context"),
3030
* required = FALSE,
3131
* ),
32-
* "field_types_context" = @ContextDefinition("any",
32+
* "field_types_context" = @ContextDefinition("string",
3333
* label = @Translation("Field types context"),
3434
* required = FALSE,
3535
* )
@@ -110,15 +110,15 @@ public function __construct(
110110
* The entity type definition.
111111
* @param array|null $bundle_context
112112
* Bundle context.
113-
* @param array|null $field_types_context
113+
* @param string|null $field_types_context
114114
* Field types context.
115115
* @param \Drupal\graphql\GraphQL\Execution\FieldContext $field_context
116116
* Field context.
117117
*/
118118
public function resolve(
119119
EntityTypeInterface $entity_definition,
120120
?array $bundle_context = NULL,
121-
?array $field_types_context = NULL,
121+
?string $field_types_context = NULL,
122122
FieldContext $field_context
123123
): \Iterator {
124124

@@ -140,14 +140,13 @@ public function resolve(
140140
}
141141

142142
if ($field_types_context) {
143-
$field_types = $field_types_context['key'];
144143
foreach ($fields as $field) {
145-
if ($field_types === 'BASE_FIELDS') {
144+
if ($field_types_context === 'BASE_FIELDS') {
146145
if ($field instanceof BaseFieldDefinition) {
147146
yield $field;
148147
}
149148
}
150-
elseif ($field_types === 'FIELD_CONFIG') {
149+
elseif ($field_types_context === 'FIELD_CONFIG') {
151150
if ($field instanceof FieldConfig || $field instanceof BaseFieldOverride) {
152151
yield $field;
153152
}

0 commit comments

Comments
 (0)