Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions docs/advanced.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- [Unions](#unions)
- [Interfaces](#interfaces)
- [Input Object](#input-object)
- [JSON Columns](#json-columns)

### Authorization

Expand Down Expand Up @@ -881,3 +882,35 @@ class TestMutation extends GraphQLType {

}
```

### JSON Columns

When using JSON columns in your database, the field won't be defined as a "relationship",
but rather a simple column with nested data. To get a nested object that's not a database relationship,
use the `non_relation_field` attribute in your Type:

```php
class UserType extends GraphQLType {

...

public function fields()
{
return [

...

// JSON column containing all posts made by this user
'posts' => [
'type' => Type::listOf(GraphQL::type('post')),
'description' => 'A list of posts written by the user',
// Now this will simply request the "posts" column, and it won't
// query for all the underlying columns in the "post" object
// The value defaults to true
'is_relation' => false
]
];
}

}
```
15 changes: 14 additions & 1 deletion src/Rebing/GraphQL/Support/SelectFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,16 @@ protected static function handleFields(array $requestedFields, $parentType, arra
// Add a query, if it exists
$customQuery = array_get($fieldObject->config, 'query');

// Check if the field is a relation that needs to be requested from the DB
$queryable = self::isQueryable($fieldObject);

// Pagination
if(is_a($parentType, PaginationType::class))
{
self::handleFields($field, $fieldObject->config['type']->getWrappedType(), $select, $with);
}
// With
elseif(is_array($field))
elseif(is_array($field) && $queryable)
{
if (isset($parentType->config['model']))
{
Expand Down Expand Up @@ -297,6 +300,16 @@ protected static function validateField($fieldObject)
return $selectable;
}

/**
* Determines whether the fieldObject is queryable.
*
* @param $fieldObject
* @return bool
*/
private static function isQueryable($fieldObject) {
return array_get($fieldObject, 'is_relation', true) === true;
}

/**
* Add selects that are given by the 'always' attribute
*/
Expand Down