Skip to content

Commit eb73ac4

Browse files
committed
Error should be collected at Schema->errors[] and include in GraphQL introspec.
1 parent a8aa87d commit eb73ac4

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

includes/graphql_api_page_callback.inc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function graphql_api_page_callback() {
3232

3333
$is_introspec = FALSE;
3434
try {
35-
if ($is_introspec && $cache = cache_get('graphql_api_introspec')) {
35+
if ($is_introspec && $cache = cache_get('graphql_api_introspec') && empty($_GET['nocache'])) {
3636
$result = $cache->data;
3737
} else {
3838
// Define your schema:
@@ -47,6 +47,13 @@ function graphql_api_page_callback() {
4747
$variableValues,
4848
$operationName
4949
);
50+
51+
if (!empty($schemaBuilder->errors)) {
52+
$result['errors'] = isset($result['errors']) ? $result['errors'] : [];
53+
$result['errors'] += $schemaBuilder->errors;
54+
$result['errors'] = array_unique($result['errors']);
55+
}
56+
5057

5158
if ($is_introspec) {
5259
cache_set('graphql_api_introspec', $result);

src/Schema.php

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class Schema {
4848
*
4949
* @var array
5050
*/
51-
private $errors = [];
51+
public $errors = [];
5252

5353

5454
private $allArgTypes = [];
@@ -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] = [
@@ -323,10 +323,6 @@ public function entityToGqlQueryArg($entity_type, $bundle = NULL) {
323323
];
324324
$this->allArgTypes[get_class($field_info['type']->ofType)] = get_class($field_info['type']->ofType);
325325
}
326-
else {
327-
$type = get_class($field_info['type']->ofType);
328-
$this->addError("Type {$type} cannot be used as args for {$field}");
329-
}
330326
}
331327
}
332328

@@ -518,8 +514,9 @@ public function getFields($entity_type, $bundle = '') {
518514
]) : Type::string();
519515

520516
if (!$fieldType) {
521-
dump($info);
522-
die("Cannot detect fieldType for {$entity_type} {$property}");
517+
// dump($info);
518+
// die("Cannot detect fieldType for {$entity_type} {$property}");
519+
$this->addError("Cannot detect fieldType for {$entity_type} {$property}");
523520
continue;
524521
}
525522

@@ -563,9 +560,9 @@ public function getFields($entity_type, $bundle = '') {
563560
]);
564561

565562
if (!$fieldType) {
566-
dump($fieldType, $field_info);
567-
die("Cannot detect field type of {$field}");
568-
$this->addError("Cannot detect field type of {$field}");
563+
// dump($fieldType, $field_info);
564+
// die("Cannot detect field type of {$field}");
565+
$this->addError("Cannot convert Drupal field type '{$field}' -> GrahpQL field type.");
569566
continue;
570567
}
571568

@@ -741,9 +738,9 @@ public function drupalToGqlFieldType($drupalType, $context = []) {
741738
}
742739

743740
if (!$type) {
744-
dump($context);
745-
die("Cannot convert {$drupalType} to GraphQL type.");
746-
$this->addError("Cannot convert {$drupalType} to GraphQL type. " . print_r($context, TRUE));
741+
// dump($context, debug_backtrace());
742+
// die("Cannot convert {$drupalType} to GraphQL type.");
743+
$this->addError("Cannot convert Drupal property type '{$drupalType}' -> GraphQL type. Please register this type with hook_graphql_api_info()");
747744
}
748745

749746
return $type;

0 commit comments

Comments
 (0)