-
-
Notifications
You must be signed in to change notification settings - Fork 269
Open
Labels
Description
Versions:
- graphql-laravel Version: 5.1.4
- Laravel Version: 8.0
- PHP Version: 7.4
Description:
The generated SQL for a group by on an interface would raise an error as * is selected instead of the group by fields
Steps To Reproduce:
<?php
class MyQuery extends Query {
public function type()
{
return Type::listOf(GraphQL::type('anInterface'));
}
public function resolve($root, $args, $context, $resolveInfo, $getSelectFields)
{
$fields = $getSelectFields();
$select = $fields->getSelect();
$with = $fields->getRelations();
$myResults = MyModel::select($select)->with($with)->groupBy('my_field')->get();
}
}
<?php
class MyInterface extends InterfaceType {
public function fields(): array
{
return [
'my_field' => ['type' => Type::string()]
]
}
}
<?php
class MyType extends Type {
public function fields(): array
{
return $interface->getFields();
}
}
With this kind of configuration, the SQL request would result in:
select * from my_table group by my_field;
And of course, it would raise an SQL error: Syntax error or access violation: 1055 Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column ...
Expectations
Only the required fields should be selected