All Projects → mesosphere → reactive-graphql

mesosphere / reactive-graphql

Licence: Apache-2.0 license
A GraphQL implementation based around RxJS, very well suited for client side only GraphQL usage

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to reactive-graphql

Connective
agent-based reactive programming library for typescript
Stars: ✭ 98 (+68.97%)
Mutual labels:  reactive, rxjs
Ayanami
🍭 A better way to react with state
Stars: ✭ 129 (+122.41%)
Mutual labels:  reactive, rxjs
Rxviz
Rx Visualizer - Animated playground for Rx Observables
Stars: ✭ 1,471 (+2436.21%)
Mutual labels:  reactive, rxjs
Inferno Most Fp Demo
A demo for the ReactJS Tampa Bay meetup showing how to build a React+Redux-like architecture from scratch using Inferno, Most.js, reactive programmning, and various functional programming tools & techniques
Stars: ✭ 45 (-22.41%)
Mutual labels:  reactive, rxjs
Awesome Reactive Programming
A repository for sharing all the resources available on Reactive Programming and Reactive Systems
Stars: ✭ 163 (+181.03%)
Mutual labels:  reactive, rxjs
Example
Example project written using Marble.js framework
Stars: ✭ 57 (-1.72%)
Mutual labels:  reactive, rxjs
React Eva
Effects+View+Actions(React distributed state management solution with rxjs.)
Stars: ✭ 121 (+108.62%)
Mutual labels:  reactive, rxjs
Push State
Turn static web sites into dynamic web apps.
Stars: ✭ 16 (-72.41%)
Mutual labels:  reactive, rxjs
Marble
Marble.js - functional reactive Node.js framework for building server-side applications, based on TypeScript and RxJS.
Stars: ✭ 1,947 (+3256.9%)
Mutual labels:  reactive, rxjs
Redux Most
Most.js based middleware for Redux. Handle async actions with monadic streams & reactive programming.
Stars: ✭ 137 (+136.21%)
Mutual labels:  reactive, rxjs
Watermelondb
🍉 Reactive & asynchronous database for powerful React and React Native apps ⚡️
Stars: ✭ 7,996 (+13686.21%)
Mutual labels:  reactive, rxjs
redrock
Typesafe, reactive redux
Stars: ✭ 14 (-75.86%)
Mutual labels:  reactive, rxjs
Dugong
Minimal State Store Manager for React Apps using RxJS
Stars: ✭ 10 (-82.76%)
Mutual labels:  reactive, rxjs
Rx Connect
Glue your state and pure React components with RxJS
Stars: ✭ 86 (+48.28%)
Mutual labels:  reactive, rxjs
Platform
Reactive libraries for Angular
Stars: ✭ 7,020 (+12003.45%)
Mutual labels:  reactive, rxjs
Rxjs In Action
Code sample repository
Stars: ✭ 117 (+101.72%)
Mutual labels:  reactive, rxjs
Frint
Modular JavaScript framework for building scalable and reactive applications
Stars: ✭ 608 (+948.28%)
Mutual labels:  reactive, rxjs
Ngx Restangular
Restangular for Angular 2 and higher versions
Stars: ✭ 787 (+1256.9%)
Mutual labels:  reactive, rxjs
Beicon
Reactive Streams for ClojureScript
Stars: ✭ 133 (+129.31%)
Mutual labels:  reactive, rxjs
rxrest
Reactive rest library
Stars: ✭ 33 (-43.1%)
Mutual labels:  reactive, rxjs

Reactive GraphQL

GraphQL reactive executor

npm version Build Status

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

Install

$ npm i reactive-graphql --save

Usage

The usage is very similar to graphql-js's graphql function, except that:

  • resolvers can return an Observable
  • the result of a query is an Observable
import { graphql } from "reactive-graphql";
import { makeExecutableSchema } from "graphql-tools";
import { timer } from "rxjs";

const typeDefs = `
  type Query {
    time: Int!
  }
`;

const resolvers = {
  Query: {
    // resolvers can return an Observable
    time: () => {
      // Observable that emits increasing numbers every 1 second
      return timer(1000, 1000);
    }
  }
};

const schema = makeExecutableSchema({
  typeDefs,
  resolvers
});

const query = `
  query {
    time
  }
`;

const stream = graphql(schema, query);
// stream is an Observable
stream.subscribe(res => console.log(res));

outputs

{ data: { time: 0 } }
{ data: { time: 1 } }
{ data: { time: 2 } }
{ data: { time: 3 } }
{ data: { time: 4 } }
...

Caveats

GraphQL Subscriptions are not supported (see issue #27) as everything is treated as subscriptions.

See Also

Advanced usage Edit

import React from "react";
import ReactDOM from "react-dom";
import "./styles.css";

import { graphql } from "reactive-graphql";

import { makeExecutableSchema } from "graphql-tools";
import { from, interval, of } from "rxjs";
import { map, merge, scan, combineLatest } from "rxjs/operators";
import { componentFromStream } from "@dcos/data-service";

// mocked API clients that return Observables
const oldPosts = from(["my first post", "a second post"]);
const newPosts = interval(3000).pipe(map(v => `Blog Post #${v + 1}`));
const fetchPosts = () =>
  oldPosts.pipe(
    merge(newPosts),
    scan((acc, item) => [...acc, item], [])
  );
const votesStore = {};
const fetchVotesForPost = name => of(votesStore[name] || 0);

const schema = makeExecutableSchema({
  typeDefs: `
  type Post {
    id: Int!
    title: String!
    votes: Int!
  }

  # the schema allows the following query:
  type Query {
    posts: [Post]
  }

  # this schema allows the following mutation:
  type Mutation {
    upvotePost (
      postId: Int!
    ): Post
  }
  `,
  resolvers: {
    Query: {
      posts(parent, args, context) {
        return fetchPosts().pipe(
          map(emittedValue =>
            emittedValue.map((value, index) => ({ id: index, title: value }))
          )
        );
      }
    },
    Post: {
      votes(parent, args, context) {
        return fetchVotesForPost(parent.title);
      }
    }
  }
});

const query = `
  query {
    posts {
      title
      votes
    }
  }
`;

const postStream = graphql(schema, query);
const PostsList = componentFromStream(propsStream =>
  propsStream.pipe(
    combineLatest(postStream, (props, result) => {
      const {
        data: { posts }
      } = result;

      return posts.map(post => (
        <div>
          <h3>{post.title}</h3>
        </div>
      ));
    })
  )
);

function App() {
  return (
    <div className="App">
      <PostsList />
    </div>
  );
}

const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);

License

Apache 2.0

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].