Skip to content

Commit ccde1c6

Browse files
authored
Merge pull request #12 from moufmouf/ignore_json_cols
Ignoring JSON columns
2 parents 1c7537c + 21298a3 commit ccde1c6

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/GraphQLTypeGenerator.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,10 @@ private function generateFieldCode(AbstractBeanPropertyDescriptor $descriptor) :
252252

253253
$type = $this->getType($descriptor);
254254

255+
if ($type === null) {
256+
return " // Field $getterName is ignored. Cannot represent a JSON field in GraphQL.";
257+
}
258+
255259
$code = <<<EOF
256260
private $variableName;
257261
@@ -269,7 +273,7 @@ protected function {$getterName}Field() : Field
269273
return $code;
270274
}
271275

272-
private function getType(AbstractBeanPropertyDescriptor $descriptor)
276+
private function getType(AbstractBeanPropertyDescriptor $descriptor) : ?string
273277
{
274278
// FIXME: can there be several primary key? If yes, we might need to fix this.
275279
// Also, primary key should be named "ID"
@@ -279,9 +283,12 @@ private function getType(AbstractBeanPropertyDescriptor $descriptor)
279283

280284
$phpType = $descriptor->getPhpType();
281285
if ($descriptor instanceof ScalarBeanPropertyDescriptor) {
286+
if ($phpType === 'array') {
287+
// JSON type cannot be casted since GraphQL does not allow for untyped arrays.
288+
return null;
289+
}
290+
282291
$map = [
283-
// TODO: how to handle JSON properties???
284-
//'array' => StringT,
285292
'string' => '\\'.StringType::class,
286293
'bool' => '\\'.BooleanType::class,
287294
'\DateTimeImmutable' => '\\'.DateTimeType::class,

0 commit comments

Comments
 (0)