You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm having problems with interface SelectFields and inline fragments.
The query seems does not extract the requested data from interface (see below query with inline fragments), maybe is related to SelectFields.
Steps To Reproduce:
Setup example
// migrations
Schema::create('humans', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('skin');
$table->timestamps();
});
Schema::create('droids', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('metal');
$table->timestamps();
});
// interface
class CharacterInterfaceType extends InterfaceType
{
protected $attributes = [
'name' => 'CharacterInterface',
'description' => 'An example interface',
];
public function fields(): array
{
return [
'id' => [
'type' => Type::id(),
],
];
}
/**
* @param $root
* @return Type
*/
public function resolveType($root): ?Type
{
$type = null;
if (! is_null($root)) {
switch (get_class($root)) {
case \App\Human::class: $type = GraphQL::type('Human'); break;
case \App\Droid::class: $type = GraphQL::type('Droid'); break;
}
}
return $type;
}
}
// types
class DroidType extends GraphQLType
{
protected $attributes = [
'name' => 'Droid',
'description' => 'A type',
'model' => Droid::class,
];
public function fields(): array
{
$characterInterface = GraphQL::type('CharacterInterface');
return array_merge($characterInterface->getFields(), [
'metal' => [
'type' => Type::string(),
'description' => 'The metal',
],
]);
}
public function interfaces(): array
{
return [
GraphQL::type('CharacterInterface')
];
}
}
class HumanType extends GraphQLType
{
protected $attributes = [
'name' => 'Human',
'description' => 'A type',
'model' => Human::class,
];
public function fields(): array
{
$characterInterface = GraphQL::type('CharacterInterface');
return array_merge($characterInterface->getFields(), [
'skin' => [
'type' => Type::string(),
'description' => 'The skin',
],
]);
}
public function interfaces(): array
{
return [
GraphQL::type('CharacterInterface')
];
}
}
// query
class CharactersQuery extends Query
{
protected $attributes = [
'name' => 'characters',
'description' => 'A query'
];
public function type(): Type
{
return Type::listOf(GraphQL::type('CharacterInterface'));
}
public function args(): array
{
return [];
}
public function resolve($root, $args, $context, ResolveInfo $resolveInfo, Closure $getSelectFields)
{
/** @var SelectFields $fields */
$fields = $getSelectFields();
$select = $fields->getSelect();
$relations = $fields->getRelations();
// this example force to human extractions
return \App\Human::select($select)->with($relations)->get(); // this not work ...
//return \App\Human::with($relations)->get(); // this not work ...
//return \App\Human::get(); // !! this work ...
}
}
Seed some human ..
Run query
query Characters {
characters {
__typename
id
...on Droid {
id
metal
}
...on Human {
id
skin
}
}
}
Check extracted data, human skin is null
The text was updated successfully, but these errors were encountered:
Versions:
Description:
I'm having problems with interface SelectFields and inline fragments.
The query seems does not extract the requested data from interface (see below query with inline fragments), maybe is related to SelectFields.
Steps To Reproduce:
The text was updated successfully, but these errors were encountered: