Quantcast
Channel: Active questions tagged symfony4 - Stack Overflow
Viewing all articles
Browse latest Browse all 3925

GraphQl query for message thread with Symfony API-Platform

$
0
0

I am trying to create a website members' message system that should work just like any web mail, where the inbox shows a conversation thread.

Getting the inbox and outbox as such seems to work, but the thread is posing some issues. So far I have been able to get all threads but I have not been able to get only the threads where a specific user is involved.

In my current set up, that would require a query that accepts OR condition, which does not seen to be available.

To be specific, in the messages query below I should be able to query for where the user appears either as sender or receiver. I can do one, not both.

It just might be the case that the whole set up is not correct.

My current query looks like below:

query(
  $user: ID!, 
  $hasChildren: MessageFilter_exists,
  $isDeletedBySender: Boolean,
  $isDeletedByReceiver: Boolean
){
user(id: $user){
id
username
  // gets all inbox messages showing parent, if exists 
inbox(isDeletedByReceiver: $isDeletedByReceiver){
  id
  sentAt
  isDeletedByReceiver
  sender{
    username
  }
  parent{
    id
  }
}
  // shows all on outbox 
outbox(isDeletedBySender: $isDeletedBySender) {
  id
  sentAt
  isDeletedBySender
  receiver{
    username
  }
}
}
 // shows ALL messages that have children, ie, a thread but IT IS NOT SPECIFIC TO THE USER
messages(exists: $hasChildren){
 id
 sender{
   id
   username
 }
 receiver{
   username
 }
 children{
  id
  sentAt
  sender...
  receiver...
 }
}

Variables:

{
  "user": "/api/users/296",
  "hasChildren": {
    "children": true
  },
  "isDeletedBySender": false,
  "isDeletedByReceiver": false
}

The User entity properties concerning messages:

/**
 * @ORM\OneToMany(targetEntity="App\Entity\Message", mappedBy="sender")
 */
private $outbox;

/**
 * @ORM\OneToMany(targetEntity="App\Entity\Message", mappedBy="receiver", orphanRemoval=true)
 */
private $inbox;

The concerned properties of the Message entity:

/**
 * @ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="outbox")
 * @ORM\JoinColumn(nullable=false)
 * @Groups({"post", "get"})
 */
private $sender;

/**
 * @ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="inbox")
 * @ORM\JoinColumn(nullable=false)
 * @Groups({"post", "get"})
 */
private $receiver;

/**
 * @ORM\ManyToOne(targetEntity="Message", inversedBy="children")
 * @ORM\JoinColumn(referencedColumnName="id", onDelete="CASCADE")
 * @Groups({"get"})
 */
private $parent;

/**
 * @ORM\OneToMany(targetEntity="Message", mappedBy="parent")
 * @ORM\OrderBy({"sentAt" = "DESC"})
 * @Groups({"get"})
 */
private $children;

Viewing all articles
Browse latest Browse all 3925

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>