All Projects → ecthiender → py-graphql-client

ecthiender / py-graphql-client

Licence: BSD-3-Clause license
Dead-simple GraphQL client with subscriptions over websockets

Programming Languages

python
139335 projects - #7 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to py-graphql-client

Djangochannelsgraphqlws
Django Channels based WebSocket GraphQL server with Graphene-like subscriptions
Stars: ✭ 203 (+463.89%)
Mutual labels:  websockets, graphql-subscriptions
Morpheus Graphql
Haskell GraphQL Api, Client and Tools
Stars: ✭ 285 (+691.67%)
Mutual labels:  graphql-client, graphql-subscriptions
Aws Lambda Graphql
Use AWS Lambda + AWS API Gateway v2 for GraphQL subscriptions over WebSocket and AWS API Gateway v1 for HTTP
Stars: ✭ 313 (+769.44%)
Mutual labels:  websockets, graphql-subscriptions
kobby
Kobby is a codegen plugin of Kotlin DSL Client by GraphQL schema. The generated DSL supports execution of complex GraphQL queries, mutation and subscriptions in Kotlin with syntax similar to native GraphQL syntax.
Stars: ✭ 52 (+44.44%)
Mutual labels:  graphql-client, graphql-subscriptions
LiveGQL
Use GraphQL Subscriptions on iOS 👌
Stars: ✭ 84 (+133.33%)
Mutual labels:  graphql-client, graphql-subscriptions
Altair
✨⚡️ A beautiful feature-rich GraphQL Client for all platforms.
Stars: ✭ 3,827 (+10530.56%)
Mutual labels:  graphql-client, graphql-subscriptions
soyuz
Real-time streaming GraphQL client for the web.
Stars: ✭ 57 (+58.33%)
Mutual labels:  graphql-client, graphql-subscriptions
36 Graphql Concepts
📜 36 concepts every GraphQL developer should know.
Stars: ✭ 209 (+480.56%)
Mutual labels:  graphql-client, graphql-subscriptions
Aws Mobile Appsync Sdk Js
JavaScript library files for Offline, Sync, Sigv4. includes support for React Native
Stars: ✭ 806 (+2138.89%)
Mutual labels:  graphql-client, graphql-subscriptions
Pup
The Ultimate Boilerplate for Products.
Stars: ✭ 563 (+1463.89%)
Mutual labels:  graphql-client, websockets
Kikstart Graphql Client
🚀 Small NodeJS Wrapper around apollo-client that provides easy access to running queries, mutations and subscriptions.
Stars: ✭ 27 (-25%)
Mutual labels:  graphql-client, graphql-subscriptions
Aws Mobile Appsync Sdk Ios
iOS SDK for AWS AppSync.
Stars: ✭ 231 (+541.67%)
Mutual labels:  graphql-client, graphql-subscriptions
golang-gqlgen-reactjs-subscription-demo
GraphQL Subscription with Golang/React JS & React Apollo Client Subscription
Stars: ✭ 29 (-19.44%)
Mutual labels:  graphql-subscriptions
vue-gql
A small and fast GraphQL client for Vue.js
Stars: ✭ 32 (-11.11%)
Mutual labels:  graphql-client
ios-graphql
iOS code examples with GraphQL, Apollo & more
Stars: ✭ 78 (+116.67%)
Mutual labels:  graphql-subscriptions
diepssect
A public repo for hacky diep stuff - networking protocol, WebAssembly, memory editing, & physics
Stars: ✭ 26 (-27.78%)
Mutual labels:  websockets
python-graphql-client
Simple module for making requests to a graphQL server in python.
Stars: ✭ 65 (+80.56%)
Mutual labels:  graphql-client
galoy-pay
A web application that can be used to send tips or payments to users
Stars: ✭ 21 (-41.67%)
Mutual labels:  graphql-client
graphql-nats-subscriptions
A graphql subscriptions implementation using nats and apollo's graphql-subscriptions
Stars: ✭ 27 (-25%)
Mutual labels:  graphql-subscriptions
go-graphql-subscription-example
☝️ go-graphql subscription over Kafka/Redis/NSQ example
Stars: ✭ 34 (-5.56%)
Mutual labels:  graphql-subscriptions

py-graphql-client

Dead-simple to use GraphQL client over websocket. Using the apollo-transport-ws protocol.

Install

pip install py-graphql-client

Examples

Setup subscriptions super easily

from graphql_client import GraphQLClient

query = """
  subscription {
    notifications {
      id
      title
      content
    }
  }
"""

with GraphQLClient('ws://localhost:8080/graphql') as client:

  sub_id = client.subscribe(query, callback=callback)
  # do other stuff
  # ...
  # later stop the subscription
  client.stop_subscribe(sub_id)

def callback(_id, data):
  print("got new data..")
  print(f"msg id: {_id}. data: {data}")

Variables can be passed

from graphql_client import GraphQLClient

query = """
    subscription ($limit: Int!) {
      notifications (order_by: {created: "desc"}, limit: $limit) {
        id
        title
        content
      }
    }
  """

with GraphQLClient('ws://localhost:8080/graphql') as client:
  sub_id = client.subscribe(query, variables={'limit': 10}, callback=callback)
  # ...

def callback(_id, data):
  print("got new data..")
  print(f"msg id: {_id}. data: {data}")

Headers can be passed too

from graphql_client import GraphQLClient

query = """
    subscription ($limit: Int!) {
      notifications (order_by: {created: "desc"}, limit: $limit) {
        id
        title
        content
      }
    }
  """

with GraphQLClient('ws://localhost:8080/graphql') as client:
  sub_id = client.subscribe(query,
                            variables={'limit': 10},
                            headers={'Authorization': 'Bearer xxxx'},
                            callback=callback)
  ...
  client.stop_subscribe(sub_id)

def callback(_id, data):
  print("got new data..")
  print(f"msg id: {_id}. data: {data}")

Normal queries and mutations work too

from graphql_client import GraphQLClient

query = """
  query ($limit: Int!) {
    notifications (order_by: {created: "desc"}, limit: $limit) {
      id
      title
      content
    }
  }
"""

with GraphQLClient('ws://localhost:8080/graphql') as client:
    res = client.query(query, variables={'limit': 10}, headers={'Authorization': 'Bearer xxxx'})
    print(res)

Without the context manager API

from graphql_client import GraphQLClient

query = """
  query ($limit: Int!) {
    notifications (order_by: {created: "desc"}, limit: $limit) {
      id
      title
      content
    }
  }
"""

client = GraphQLClient('ws://localhost:8080/graphql')
res = client.query(query, variables={'limit': 10}, headers={'Authorization': 'Bearer xxxx'})
print(res)
client.close()

TODO

  • support http as well
  • should use asyncio websocket library?
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].