# How to implement direct - reverse query for real time chat

**URL:** <https://discuss.dgraph.io/t/how-to-implement-direct-reverse-query-for-real-time-chat/16399>\
**Category:** GraphQL\
**Tags:** subscription\
**Created:** [December 24, 2021, 8:40am UTC](https://discuss.dgraph.io/t/how-to-implement-direct-reverse-query-for-real-time-chat/16399 "2021-12-24T08:40:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![skiv86](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/skiv86/32/6070_2.png) [@skiv86](https://discuss.dgraph.io/u/skiv86)\
**Post date:** [December 24, 2021, 8:40am UTC](https://discuss.dgraph.io/t/how-to-implement-direct-reverse-query-for-real-time-chat/16399/1 "2021-12-24T08:40:52Z")

</div>

i want take data for chat room beetween two users by subscription  
i have schema like this

```auto
type User @withSubscription {
	id: ID! 
	name: String! 
	email: String! 
	messages: [Message] 
}

type Message @withSubscription {
	id: ID! 
	message: String! 
	senderMail: String! @search(by: [hash, regexp, term])
	receiverMail: String! @search(by: [hash, regexp, term])
	timestamp: DateTime! 
	users: [User] 
}

```

and take data like this

```auto
useSubscription(SUBSCRIPTION_QUERY,
        {
            variables: {filter: { senderMail: {in: [senderMail] }, receiverMail: {in: [email]}}},
        }
    );

```

but it give data only in one way - for sender email Messages only

i need to create new subscription like this

```auto
useSubscription(SUBSCRIPTION_QUERY,
        {
            variables: {filter: { senderMail: {in: [email] }, receiverMail: {in: [senderMail]}}},
        }
    );

```

it gives messages from recieverMail too

but maybe be way to create subscription for both cases

---

<div class="post-metadata">

**Author:** ![amaster507](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/amaster507/32/4123_2.png) [@amaster507](https://discuss.dgraph.io/u/amaster507)\
**Post date:** [December 24, 2021, 2:32pm UTC](https://discuss.dgraph.io/t/how-to-implement-direct-reverse-query-for-real-time-chat/16399/2 "2021-12-24T14:32:34Z")

</div>

Wrap them in `filter: { OR: [{ senderMail: ... }, { receiverMail: ... }]}`

Without specifying the logic it defaults to `AND`
