Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

Commit

Permalink
feat: complete implementation (fragments, introspection...)
Browse files Browse the repository at this point in the history
BREAKING CHANGE:
- Removed support for Observable rootValue
- Removed the support for Observable variables: If necessary, it can be done by the user with a simple:

```js
variables$.pipe(
  switchMap(variables => graphql({ schema, source: query, variables }))
)
```
- Removed support for query as Document in graphql(): 
```js
// previously ok:
graphql(schema, gql`query {}`)

// now use:
execute(schema, gql`query {}`)
// or 
graphql(schema, `query {}`)
```
- Error handling: every expected errors (validation, syntax error, throwing resolver...) are pushed in the error field of the ExecutionResult, the RxJS stream does not throw in these cases anymore
  • Loading branch information
alexstrat authored and Daniel Schmidt committed Sep 30, 2019
1 parent 0f3f455 commit ccfa24b
Show file tree
Hide file tree
Showing 19 changed files with 1,574 additions and 573 deletions.
25 changes: 5 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

Execute GraphQL queries against reactive resolvers (resolvers that return Observable) to get a reactive results.

_This project aims to become a complete GraphQL implementation based around [RxJS](https://github.com/ReactiveX/rxjs)._

## Install

```
Expand All @@ -19,13 +17,12 @@ $ npm i reactive-graphql --save
The usage is very similar to `graphql-js`'s [`graphql`](https://graphql.org/graphql-js/graphql/#graphql) function, except that:

- resolvers can return an Observable
- the returned value is an Observable
- the result of a query is an Observable

```js
import { graphql } from "reactive-graphql";
import { makeExecutableSchema } from "graphql-tools";
import gql from "graphql-tag";
import { timer } from "rxjs";
import graphql from "reactive-graphql";

const typeDefs = `
type Query {
Expand All @@ -48,13 +45,13 @@ const schema = makeExecutableSchema({
resolvers
});

const query = gql`
const query = `
query {
time
}
`;

const stream = graphql(query, schema);
const stream = graphql(schema, query);
// stream is an Observable
stream.subscribe(res => console.log(res));
```
Expand All @@ -70,20 +67,8 @@ outputs
...
```

## API

The first argument you pass into `reactive-graphql` is a GraphQL query, either parsed or as string, the second one is an executable schema. You can pass in the root context as an object as a third parameter. The variables can be passed as 4th parameter.

The implementation will always return an Observable.
If any of the resolvers returns an error the implementation will emit the error on the stream.
Otherwise the data will be wrapped in a `{ data }` object, like most implementations handle this.

## Caveats

Unsupported GraphQL features:

- fragments of all kinds
- subscriptions (as everything is treated as a subscription)
GraphQL Subscriptions are not supported (see [issue #27](https://github.com/mesosphere/reactive-graphql/issues/27)) as everything is treated as subscriptions.

## See Also

Expand Down
Loading

0 comments on commit ccfa24b

Please sign in to comment.