python-graphql-client icon indicating copy to clipboard operation
python-graphql-client copied to clipboard

What is the chance to add Subscription ?

Open SebaBoler opened this issue 7 years ago • 12 comments

Hey, your client works perfect with Query and Mutation. Its any chance to add Subscription support >>??

SebaBoler avatar Sep 26 '18 10:09 SebaBoler

Thanks. This is a good suggestion. I will look into it. The newer python versions support async out of the box. I am not 100% familiar with subscribe, but I imagine passing an async iterable to a call back function.

ssshah86 avatar Sep 26 '18 15:09 ssshah86

If you need i can create server GraphQL with few subscription to test?

SebaBoler avatar Sep 27 '18 16:09 SebaBoler

That would be nice thanks. This might take me some time. If anyone would like to contribute I'm happy to review.

ssshah86 avatar Oct 01 '18 09:10 ssshah86

Any chance to write anything in actual month??

SebaBoler avatar Oct 13 '18 12:10 SebaBoler

Yea I can. Can you get the test server up?

ssshah86 avatar Oct 31 '18 03:10 ssshah86

ofc, give me 2 days. I will send info

SebaBoler avatar Nov 02 '18 18:11 SebaBoler

Any updates on the issue?

ghost avatar Dec 24 '18 15:12 ghost

I haven't had any time to work on this, but I am still waiting for the test server info.

ssshah86 avatar Jan 03 '19 17:01 ssshah86

Websocket support would indeed be great, so we can have subscriptions :)

waterdrop01 avatar Feb 27 '19 08:02 waterdrop01

Can you provide more details on how you would like to use a subscription API? It will help me determine the best interface.

ssshah86 avatar Feb 28 '19 21:02 ssshah86

Sorry I fear I'm not familiar enough with Python and its async library to provide a relevant feedback in API design.

In JS, this doc shows how subscription client is created, and here is the subscription API:

apolloClient.subscribe({
  query: gql`
    subscription onNewItem {
        newItemCreated {
            id
        }
    }`,
  variables: {}
}).subscribe({
  next (data) {
    // Notify your application with the new arrived data
  }
});

Also, you may have a look at this Python gql client that apparently supports subscriptions: https://github.com/tdip/gql-subscriptions/tree/develop

waterdrop01 avatar Mar 05 '19 11:03 waterdrop01

Thanks, this is helpful. I wrote something far simpler than tdip's gql subscriptions package. I also use websockets, but the problem is that the connection must be kept alive with a while True statement. I've posted the question here https://github.com/aaugustin/websockets/issues/581

I'm thinking of keeping the API very basic so the keep-alive problem is transferred to the developer for now. The only use case I'm testing against is whenever a subscription is received, the payload is printed. I can commit the code this weekend.

ssshah86 avatar Mar 05 '19 19:03 ssshah86