Skip to content
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

[GraphQL Issue] Get subresource fields with serialization groups #1645

Open
bastoune opened this issue Sep 8, 2020 · 0 comments
Open

[GraphQL Issue] Get subresource fields with serialization groups #1645

bastoune opened this issue Sep 8, 2020 · 0 comments

Comments

@bastoune
Copy link

bastoune commented Sep 8, 2020

API Platform version(s) affected: v2.5.7

Description
Using serialization groups, I want to show field of a linked resource.
For example, a User have an Organization
User

 * @ApiResource(
 *     normalizationContext={"groups"={"User:read"}},
 *     denormalizationContext={"groups"={"User:write"}},
 *     graphql={
 *         "item_query"={"normalization_context"={"groups"={"User:read"}}},
 *         "collection_query"={"normalization_context"={"groups"={"User:read"}}},
 *     }
 * )
[....]
    /**
     * @Groups({"User:read"})
     * @ORM\ManyToOne(targetEntity="Organization", inversedBy="users")
     * @ORM\JoinColumn(name="organization_id", referencedColumnName="id", nullable=true)
     */
    private $organization;

Organization

 * @ApiResource(
 *     graphql={
 *         "item_query"={"normalization_context"={"groups"={"Organization:read"}}},
 *         "collection_query"={"normalization_context"={"groups"={"Organization:read"}}},
 *     }
 * )
[...]
    /**
     * @Groups({"User:read"})
     * @ORM\Column(type="string", length=255, unique=true)
     */
    private $name;

I want to execute this request :

  users {
    edges {
      node {
        email,
        organization {
          id, name
        }
      }
    }
  }
}

The attribute name isn't in the doc and the request fails with this error `Cannot query field "name" on type "Organization".``

How to reproduce
Here is a github project to reproduce : https://github.com/bastoune/api-platform-test-project/tree/issue/SerializationGroups

Additional context
This behaviour perfectly works in Rest

This is possibly linked with this issue : #1636

@bastoune bastoune changed the title [GraphQL Issue] Get subresource fields thanks to serialization groups [GraphQL Issue] Get subresource fields with serialization groups Sep 8, 2020
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

1 participant