Re: [django-channels] post-process message from Group

2018-01-18 Thread Tomáš Ehrlich
Hey Andrew,
that's great! I'll take a look today. For some reason, I didn't receive 
your response so I came up with a bit inefficient solution described in 
this 
[gist](https://gist.github.com/tricoder42/af3d0337c1b33d82c1b32d12bd0265ec).

I basically have another store with subscribers and then broadcast message 
manually.

Anyway, going to wipe it out and start over using Channels 2 :)


Thanks for a great library!

Cheers,
   Tom

Dne středa 17. ledna 2018 19:43:23 UTC+1 Andrew Godwin napsal(a):
>
> Hi Tom,
>
> In Channels 1, because of the way Groups work you cannot do 
> post-processing. The only fix for this is a complete rearchitecture which 
> is underway in Channels 2, where you get the ability to act on group 
> messages before they get sent back to the consumer.
>
> Channels 2 is not yet ready for production, but is close, and if you want 
> to start playing around with it now you can: 
> http://channels.readthedocs.io/en/2.0/
>
> Andrew
>
> On Wed, Jan 17, 2018 at 5:42 AM, Tomáš Ehrlich  > wrote:
>
>> Hello everyone,
>> I’m trying to connect django-channels with GraphQL subscriptions (using 
>> graphene and underlying graphql-core library).
>>
>> I’m basically doing sth similar to example in [docs](
>> https://channels.readthedocs.io/en/latest/concepts.html#groups):
>>
>> - I setup listener of post_save signal, passing instance PK to Group
>> - When subscription is requested, I add reply_channel to the Group I want 
>> to listen
>>
>> The problem is that with GraphQL I don’t know in advance what data client 
>> requests. 
>> Compared to DRF where I could simply serialize instance in post_save 
>> listener and send
>> serialized data to Group, here I’m only sending instance PK (each client 
>> might request different fields from
>> model and I can’t pass instances through channel). Ideally, instead of 
>> adding reply_channel
>> to the Group directly, I would like to add custom callback, which 1) gets 
>> instance by PK 2) serialize it using
>> given GraphQL query and finally 3) send data to reply_channel.
>>
>>
>> Other possible workaround: list channels in a group
>>
>> I think I could save query (== serializer) to channel_session and execute 
>> it (== serialize instance) when message is received. 
>> Then I need to add a consumer for a Group and for that I would need to 
>> list all channels in a Group.
>>
>>
>> Any ideas? GraphQL is still new in Djangoland and especially 
>> subscriptions are sth which needs to be figured out…
>>
>>
>> Thank you in advance!
>>
>> Cheers,
>>Tom
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com 
>> .
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/3506375B-E9B4-4F99-96D0-AD18F78B8CE9%40gmail.com
>>  
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/fd7ebbdf-c278-42a5-bd6c-f5d7ea3c9356%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [django-channels] post-process message from Group

2018-01-17 Thread Andrew Godwin
Hi Tom,

In Channels 1, because of the way Groups work you cannot do
post-processing. The only fix for this is a complete rearchitecture which
is underway in Channels 2, where you get the ability to act on group
messages before they get sent back to the consumer.

Channels 2 is not yet ready for production, but is close, and if you want
to start playing around with it now you can:
http://channels.readthedocs.io/en/2.0/

Andrew

On Wed, Jan 17, 2018 at 5:42 AM, Tomáš Ehrlich 
wrote:

> Hello everyone,
> I’m trying to connect django-channels with GraphQL subscriptions (using
> graphene and underlying graphql-core library).
>
> I’m basically doing sth similar to example in [docs](https://channels.
> readthedocs.io/en/latest/concepts.html#groups):
>
> - I setup listener of post_save signal, passing instance PK to Group
> - When subscription is requested, I add reply_channel to the Group I want
> to listen
>
> The problem is that with GraphQL I don’t know in advance what data client
> requests.
> Compared to DRF where I could simply serialize instance in post_save
> listener and send
> serialized data to Group, here I’m only sending instance PK (each client
> might request different fields from
> model and I can’t pass instances through channel). Ideally, instead of
> adding reply_channel
> to the Group directly, I would like to add custom callback, which 1) gets
> instance by PK 2) serialize it using
> given GraphQL query and finally 3) send data to reply_channel.
>
>
> Other possible workaround: list channels in a group
>
> I think I could save query (== serializer) to channel_session and execute
> it (== serialize instance) when message is received.
> Then I need to add a consumer for a Group and for that I would need to
> list all channels in a Group.
>
>
> Any ideas? GraphQL is still new in Djangoland and especially subscriptions
> are sth which needs to be figured out…
>
>
> Thank you in advance!
>
> Cheers,
>Tom
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/3506375B-E9B4-4F99-96D0-AD18F78B8CE9%40gmail.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFwN1uou3ATW_NpYUBh3BgcDf%2BuG-OutsJXQH1CpEd3wRSMHcw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.