prisma-labs / python-graphql-client

Simple GraphQL client for Python 2.7+
MIT License
156 stars 46 forks source link

What is the chance to add Subscription ? #11

Open SebaBoler opened 5 years ago

SebaBoler commented 5 years ago

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

ssshah86 commented 5 years ago

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.

SebaBoler commented 5 years ago

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

ssshah86 commented 5 years ago

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

SebaBoler commented 5 years ago

Any chance to write anything in actual month??

ssshah86 commented 5 years ago

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

SebaBoler commented 5 years ago

ofc, give me 2 days. I will send info

ghost commented 5 years ago

Any updates on the issue?

ssshah86 commented 5 years ago

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

waterdrop01 commented 5 years ago

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

ssshah86 commented 5 years ago

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

waterdrop01 commented 5 years ago

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

ssshah86 commented 5 years ago

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.