Skip to content

GraphqQl does not allow input embedded relation #3694

Description

@BernardA

API Platform version(s) affected: "api-platform/api-pack": "^1.2",

Description
Fetching contacts from GooglePeopleApi and attempting to adding them to existing user.

Google provides an array of contacts.

I am following this comment from @dunglas #1645 (comment), and setting up a relation that share the same groups on the denormalization context for the operation updateUser.

I was expecting to be able to have the full Contact entity as an input to updateUser, but graphiql will only expect an array of strings, ie, contacts: [String] ( see screenshot below)

How to reproduce
( only relevant code )
The USER entity :

    *          "update"={
    *              "security"="(is_granted('IS_AUTHENTICATED_FULLY') and object == user) or is_granted('ROLE_ADMIN')",
    *              "denormalization_context"={
    *                  "groups"={"put-profile-change", "put-contacts", "put"}
    *              },
    *              "validation_groups"={"put-profile-change"}
    *          },

   .....

 /**
  * @ORM\OneToMany(targetEntity="App\Entity\Contact", mappedBy="user")
  * @Groups({"put", "put-contacts", "get-admin", "get-owner"})
  */
 private $contacts;

The CONTACT entity:

 *          "create"={
 *              "security"="is_granted('IS_AUTHENTICATED_FULLY')",
 *              "denormalization_context"={"groups"={"post", "put", "put-contacts"}},
 *              "normalization_context"={"groups"={"get-owner", "get-admin"}},
 *          },
 *          "update"={
 *              "security"="(is_granted('IS_AUTHENTICATED_FULLY') and object == user) or is_granted('ROLE_ADMIN')",
 *              "denormalization_context"={
 *                  "groups"={"put-contacts", "put"}
 *              },
 *          },

 ....


/**
 * @ORM\Id()
 * @ORM\GeneratedValue()
 * @ORM\Column(type="integer")
 * @Groups({"put", "put-contacts", "get-admin", "get-owner"})
 */
private $id;

/**
 * @ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="contacts")
 * @Groups({"post", "put", "put-contacts", "get-admin", "get-owner"})
 */
private $user;

/**
 * @ORM\Column(type="string", length=180)
 * @Groups({"post", "put", "put-contacts", "get-admin", "get-owner"})
 */
private $email;

Possible Solution

Additional Context
Update user input:
Screenshot 2020-08-29 at 12 33 12

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions