Skip to content

cannot perform GraphQL sub-selections on non-resource collections #3016

@ehough

Description

@ehough

This issue is related to #2740 and #2687, but it's different enough that I felt it deserves a separate issue.

I'm having trouble performing sub-selection queries on non-doctrine, non-resource collections. Here's an example. Say I have a very simple resource class:

/**
 * @ApiResource
 */
class Book
{
    /**
     * @ApiProperty(identifier=true)
     *
     * @var string
     */
    public $id;

    /**
     * @var Chapter[]
     */
    public $chapters;
}

with Chapter is a simple POPO:

class Chapter
{
    /**
     * @var int
     */
    public $startingPage;

    /**
     * @var string
     */
    public $name;
}

For testing purposes I have custom data provider that serves dummy instances of books, each with several chapters. I also have a Normalizer that handles normalizing Chapters. This works well initially:

basic query

But say I want to fetch only the chapter names, I run into the following error:

Field \"chapters\" of type \"Iterable!\" must not have a sub selection.

sub-selection errors

This is a contrived example, of course, but you can imagine some of the properties on the nested object being bandwidth-heavy or expensive to compute.

I saw that there has been quite a bit of refactoring of the GraphQL code in master, but unfortunately I'm experiencing this issue with both the 2.4 branch as well as master. I also tried to go through the GraphQL code but I'll admit that it's a bit over my head.

Any guidance would be appreciated. Thanks!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions