Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rob-blackbourn/barejs-graphql-observable
An observable GraphQL client for use with the bareASGI web toolkit
https://github.com/rob-blackbourn/barejs-graphql-observable
bareasgi graphql javascript observable rxjs
Last synced: about 1 month ago
JSON representation
An observable GraphQL client for use with the bareASGI web toolkit
- Host: GitHub
- URL: https://github.com/rob-blackbourn/barejs-graphql-observable
- Owner: rob-blackbourn
- License: apache-2.0
- Created: 2019-08-15T09:40:41.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-07-20T04:52:38.000Z (over 2 years ago)
- Last Synced: 2024-08-09T21:10:25.995Z (3 months ago)
- Topics: bareasgi, graphql, javascript, observable, rxjs
- Language: TypeScript
- Size: 130 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# @barejs/graphql-observable
This is a collection of observable GraphQL clients which support queries, mutations and subscriptions.
It uses the
[rxjs](https://rxjs-dev.firebaseapp.com/)
observable library.It specifically targets the
[bareASGI GraphQL](https://github.com/rob-blackbourn/bareASGI-graphql-next)
module from the
[bareASGI](https://github.com/rob-blackbourn/bareASGI)
python web framework, which provides multiple transports for subscriptions.This is a thin wrapper around
[@barejs/graphql-client](https://github.com/rob-blackbourn/barejs-graphql-client)
where more documentation can be found.## Usage
### Subscriptions
The `graphqlObservableWsSubscriber` function used be used for subscriptions.
```js
import { graphqlObservableWsSubscriber } from '@barejs/graphql-observable'const url = 'http://www.example.com/subscriptions'
const init = {}const query = 'subscription { someSubscription { someField someOtherField } }'
const variables = null
const operationName = nullsubscription = graphqlObservableWsSubscriber(url, init, query, variables, operationName).subscribe({
next: data => console.log(data),
error: error => console.error(error),
complete: () => console.log('Completed')
})
```### Queries, Mutations and Subscriptions
The `graphqlObservableWsClient` can be used for queries, mutations, and subscriptions.
```js
import { graphqlObservableWsClient } from '@barejs/graphql-observable'const url = 'http://www.example.com/graphql'
const init = {}// This could be a query, mutation or subscription.
const query = 'subscription { someSubscription { someField someOtherField } }'
const variables = null
const operationName = nullconst subscription = graphqlObservableWsClient(
url,
init,
query,
variables,
operationName)
.subscribe({
next: data => console.log(data),
error: error => console.log(error),
complete: () => console.log('complete')
})// Later ...
subscription.unsubscribe()
```### Other transports
In addition to the fetch/WebSocket transports there is support for `EventSource` and streaming fetch, although these are only supported by the bareASGI web framework.
The following functions are available:
* graphqlObservableEventSourceClient,
* graphqlObservableEventSourceSubscriber,
* graphqlObservableFetchClient,
* graphqlObservableStreamClient,
* graphqlObservableWsClient,
* graphqlObservableWsSubscriberAll of the clients abd subscribers take the same arguments as the WebSocket variant.