Skip to content

Commit e23390d

Browse files
committed
don't warn if bundle properties are empty
1 parent 4e1230f commit e23390d

File tree

1 file changed

+38
-33
lines changed

1 file changed

+38
-33
lines changed

src/Schema.php

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ public function entityToGqlQueryArg($entity_type, $bundle = NULL) {
314314
if ($field_info['type'] instanceof ListOfType) {
315315
if (isset($this->objectTypes[$field])) {
316316
$field_info['type'] = $this->objectTypes[$field];
317-
}
317+
}
318318
else {
319319
if (!($field_info['type']->ofType instanceof \Closure) && !($field_info['type']->ofType instanceof InterfaceType)) {
320320
$args[$field] = [
@@ -505,39 +505,41 @@ public function getFields($entity_type, $bundle = '') {
505505

506506
$entity_info = $this->getEntityInfo($entity_type);
507507
$entity_keys = $entity_info['entity keys'];
508-
foreach ($properties_info['properties'] as $property => $info) {
509-
$fieldType = isset($info['type']) ? $this->gqlFieldType($info['type'], [
510-
'entity_type' => $entity_type,
511-
'bundle' => NULL,
512-
'property' => $property,
513-
'info' => $info
514-
]) : Type::string();
515-
516-
if (!$fieldType) {
517-
// dump($info);
518-
// die("Cannot detect fieldType for {$entity_type} {$property}");
519-
$this->addError("Cannot detect fieldType for {$entity_type} {$property}");
520-
continue;
521-
}
508+
if ($properties_info['properties']) {
509+
foreach ($properties_info['properties'] as $property => $info) {
510+
$fieldType = isset($info['type']) ? $this->gqlFieldType($info['type'], [
511+
'entity_type' => $entity_type,
512+
'bundle' => NULL,
513+
'property' => $property,
514+
'info' => $info
515+
]) : Type::string();
516+
517+
if (!$fieldType) {
518+
// dump($info);
519+
// die("Cannot detect fieldType for {$entity_type} {$property}");
520+
$this->addError("Cannot detect fieldType for {$entity_type} {$property}");
521+
continue;
522+
}
522523

523-
$fields[$property] = [
524-
'type' => $fieldType,
525-
'description' => isset($info['description']) ? $info['description'] : '',
526-
'resolve' => function ($value, $args, $context, ResolveInfo $info) use ($entity_type, $bundle, $property) {
527-
if (isset($value->wrapper)) {
528-
$wrap = $value->wrapper();
529-
} else {
530-
$wrap = entity_metadata_wrapper($entity_type, $value);
524+
$fields[$property] = [
525+
'type' => $fieldType,
526+
'description' => isset($info['description']) ? $info['description'] : '',
527+
'resolve' => function ($value, $args, $context, ResolveInfo $info) use ($entity_type, $bundle, $property) {
528+
if (isset($value->wrapper)) {
529+
$wrap = $value->wrapper();
530+
} else {
531+
$wrap = entity_metadata_wrapper($entity_type, $value);
532+
}
533+
$items = $wrap->{$property}->value();
534+
return $items;
531535
}
532-
$items = $wrap->{$property}->value();
533-
return $items;
536+
];
537+
if (in_array($property, [
538+
$entity_keys['id'],
539+
$entity_keys['revision']
540+
])) {
541+
$fields[$property]['type'] = Type::id();
534542
}
535-
];
536-
if (in_array($property, [
537-
$entity_keys['id'],
538-
$entity_keys['revision']
539-
])) {
540-
$fields[$property]['type'] = Type::id();
541543
}
542544
}
543545

@@ -581,7 +583,10 @@ public function getFields($entity_type, $bundle = '') {
581583
break;
582584
case 'entityreference':
583585
$target_type = $field_info['settings']['target_type'];
584-
$target_bundles = array_values($field_info['settings']['handler_settings']['target_bundles']);
586+
$target_bundles = array();
587+
if (is_array($field_info['settings']['handler_settings']['target_bundles'])) {
588+
$target_bundles = array_values($field_info['settings']['handler_settings']['target_bundles']);
589+
}
585590
if (empty($target_bundles)) {
586591
$target_bundles = array_keys($self->getEntityInfo($target_type)['bundles']);
587592
}
@@ -746,4 +751,4 @@ public function drupalToGqlFieldType($drupalType, $context = []) {
746751
return $type;
747752
}
748753

749-
}
754+
}

0 commit comments

Comments
 (0)