diff --git a/CHANGELOG.md b/CHANGELOG.md index 25f6fd2..319428d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ - Minimum PHP version increased to 8.1 - Updated [Rebing/GraphQL](https://github.com/rebing/graphql-laravel) Dependency from version 8.6 to 9.2 - Updated [Rcrowe/TwigBridge](https://github.com/rcrowe/TwigBridge) Dependency from version 0.14.1 to 0.14.3 +- Relaxed GraphQL handling of fieldtypes during schema generation. Now errors will be logged but schemas can still be built ## [1.4.0] - 2024-08-12 diff --git a/src/Api/Graph/Support/FieldtypeRegistrar.php b/src/Api/Graph/Support/FieldtypeRegistrar.php index 3bea060..0b0a211 100644 --- a/src/Api/Graph/Support/FieldtypeRegistrar.php +++ b/src/Api/Graph/Support/FieldtypeRegistrar.php @@ -116,6 +116,12 @@ public function registerField(ChannelField $field) $name = "Field__{$field->field_name}"; $typeDefinition = $fieldtype->generateGraphType($field); + if (empty($typeDefinition)) { + app('log')->error(vsprintf('Field %s (%s) implements %s but returns an empty GraphQL Type.', [$field->field_name, $field->field_type, GeneratesGraphType::class])); + + return null; + } + if (! $typeDefinition instanceof GraphQLType) { throw new \Exception("Generated GraphQL Type for field {$field->field_name} must extend ".GraphQLType::class.'.'); } @@ -167,8 +173,12 @@ public function getTypeForField($field) ]); $type = array_shift($possibleTypes); + + // If we can't find a Type we log the error and fallback to String so the schema can still be constructed if ($type === null) { - dd($field->field_name, $field->field_type, $field->getFieldType(), $this->types); + app('log')->error(vsprintf('Cannot find GraphQL Type for field %s (%s)', [$field->field_name, $field->field_type])); + + return null; } $type = ($field->getFieldtype() instanceof ListsGraphType && ! ($type instanceof ListOfType)) ? Type::listOf($type) : $type;