Skip to content

Multiple ManyToMany on same class gives inconsistent results with GraphQL #5256

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
remyber opened this issue Dec 8, 2022 · 1 comment
Closed

Comments

@remyber
Copy link

remyber commented Dec 8, 2022

API Platform version(s) affected: 3.0.6

Description
In an entity, I create several ManyToMany relations pointing to the same class. When retrieving data via a GraphQL query, all relations display the same results.

How to reproduce
Here is a minimalist entity affected by the bug:

#[ORM\Table(name: 'tests')]
#[ORM\Entity]
#[ApiResource(
    graphQlOperations: [new QueryCollection()]
)]
class Test
{
    #[ApiProperty(identifier: false)]
    #[ORM\Column(name: 'id', type: 'integer')]
    #[ORM\Id]
    #[ORM\GeneratedValue(strategy: 'AUTO')]
    private ?int $id = null;

    #[ApiProperty(identifier: true)]
    #[ORM\Column(type: 'uuid', unique: true)]
    private UuidInterface $uuid;

    #[ORM\JoinTable(name: 'tests_users1')]
    #[ORM\ManyToMany(targetEntity: User::class)]
    private iterable $users1;

    #[ORM\JoinTable(name: 'tests_users2')]
    #[ORM\ManyToMany(targetEntity: User::class)]
    private iterable $users2;

    public function __construct()
    {
        $this->uuid = Uuid::uuid4();

        $this->users1 = new ArrayCollection();
        $this->users2 = new ArrayCollection();
    }

    public function getId(): ?int
    {
        return $this->id;
    }

    public function getUuid(): UuidInterface
    {
        return $this->uuid;
    }

    public function getUsers1(): iterable
    {
        return $this->users1;
    }

    public function getUsers2(): iterable
    {
        return $this->users2;
    }

To test, I added an entry in tests_users2. tests_users1 is empty.
Here is the GraphQL query:

{
  tests {
    id
    users1 {
      collection {
        username
      }
    }
    users2 {
      collection {
        username
      }
    }
  }
}

And the results. The 2 relations show the same results, while users1 should be empty.

{
  "data": {
    "tests": [
      {
        "id": "/api/tests/92aaea46-def9-4cb6-84ee-ef8954c4a894",
        "users1": {
          "collection": [
            {
              "username": "test51"
            }
          ]
        },
        "users2": {
          "collection": [
            {
              "username": "test51"
            }
          ]
        }
      }
    ]
  }
}
@remyber remyber changed the title Multiple ManyToMany on same class gives inconsistent results Multiple ManyToMany on same class gives inconsistent results with GraphQL Dec 8, 2022
@webda2l
Copy link
Contributor

webda2l commented Dec 9, 2022

See #5169

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants