ecthiender / py-graphql-client

Dead-simple GraphQL client with subscriptions over websockets
https://pypi.org/project/py-graphql-client/
Other
37 stars 11 forks source link

GraphQL Http client #5

Closed BharathaAravind closed 4 years ago

BharathaAravind commented 5 years ago

A Basic Http Client to support Query and Mutations over http.

Sample Query Usage:

from  graphql_client import GraphQLHttpClient

httpClient = GraphQLHttpClient.GraphQLHttpClient("http://localhost:8080/graphql")
q = """
  query ($limit: Int!) {
    notifications (order_by: {created: "desc"}, limit: $limit) {
      id
      title
      content
    }
  }
"""
response = httpClient.query(query=q, variables={'limit': 10})
print(response.text)

Even the mutation works the same way. It internally calls query itself.

from  graphql_client import GraphQLHttpClient
httpClient = GraphQLHttpClient.GraphQLHttpClient("http://localhost:8080/graphql")
mutation = """
  mutation{
    uploadData(file:"xxx/somefilepath.txt"){
    id
  }
}
"""
response = httpClient.mutation(query=mutation)
ecthiender commented 4 years ago

There should be one client which can use a specified transport (HTTP or websocket). Closing this in favour of a better design in #17 .

Thanks for all your work @BharathaAravind . Please feel free to contribute anything else, if you would like.