Skip to content

Commit

Permalink
Change GraphQL schema to allow generation while fieldtype errors are …
Browse files Browse the repository at this point in the history
…logged
  • Loading branch information
bryannielsen committed Sep 26, 2024
1 parent e967c2f commit dac88be
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.2] - 2024-09-26

Expand Down
12 changes: 11 additions & 1 deletion src/Api/Graph/Support/FieldtypeRegistrar.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.'.');
}
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit dac88be

Please sign in to comment.