Skip to content

Commit 8c766a3

Browse files
authored
Merge pull request #13 from thecodingmachine/fix_json_columns
Fixing handling of JSON columns (they are now ignored)
2 parents ccde1c6 + c1ef22d commit 8c766a3

File tree

4 files changed

+35
-2
lines changed

4 files changed

+35
-2
lines changed

.travis.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,20 @@ php:
44
cache:
55
directories:
66
- $HOME/.composer/cache
7+
8+
services:
9+
- mysql
10+
11+
addons:
12+
apt:
13+
sources:
14+
- mysql-5.7-trusty
15+
packages:
16+
- mysql-server
17+
18+
dist: trusty
19+
sudo: required
20+
721
env:
822
matrix:
923
- PREFER_LOWEST="--prefer-lowest"

src/AbstractTdbmGraphQLTypeMapper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ private function mapTypeToInputType(TypeInterface $type): InputTypeInterface
9999

100100
$this->typeToInputTypes->attach($type, $inputType);
101101

102-
$inputFields = array_map(function(\Youshido\GraphQL\Field\FieldInterface $field) {
102+
$inputFields = array_map(function (\Youshido\GraphQL\Field\FieldInterface $field) {
103103
$type = $field->getType();
104104
/*if ($type instanceof NonNullType) {
105105
return new NonNullType($this->mapTypeToInputType($type->getNullableType()));

src/GraphQLTypeGenerator.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ private function generateAbstractTypeFile(BeanDescriptorInterface $beanDescripto
8686
$typeName = var_export($this->namingStrategy->getGraphQLType($beanDescriptor->getBeanClassName()), true);
8787

8888
$properties = $beanDescriptor->getExposedProperties();
89+
90+
$properties = array_filter($properties, [$this, 'canBeCastToGraphQL']);
91+
8992
$fieldsCodes = array_map([$this, 'generateFieldCode'], $properties);
9093

9194
$fieldsCode = implode('', $fieldsCodes);
@@ -243,6 +246,21 @@ public function alter(): void
243246
$fileSystem->dumpFile($filePaths[0], $str);
244247
}
245248

249+
/**
250+
* Some fields cannot be bound to GraphQL fields (for instance JSON fields)
251+
*/
252+
private function canBeCastToGraphQL(AbstractBeanPropertyDescriptor $descriptor) : bool
253+
{
254+
if ($descriptor instanceof ScalarBeanPropertyDescriptor) {
255+
$phpType = $descriptor->getPhpType();
256+
if ($phpType === 'array') {
257+
// JSON type cannot be casted since GraphQL does not allow for untyped arrays.
258+
return false;
259+
}
260+
}
261+
return true;
262+
}
263+
246264
private function generateFieldCode(AbstractBeanPropertyDescriptor $descriptor) : string
247265
{
248266
$getterName = $descriptor->getGetterName();

tests/sql/graphqlunittest.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@ CREATE TABLE IF NOT EXISTS `users` (
158158
`login` varchar(255) NOT NULL,
159159
`password` varchar(255) DEFAULT NULL,
160160
`status` varchar(10) DEFAULT NULL,
161-
`country_id` int(11) NOT NULL
161+
`country_id` int(11) NOT NULL,
162+
`additional_data` JSON NULL
162163
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
163164

164165
-- --------------------------------------------------------

0 commit comments

Comments
 (0)