Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create repositories and basic implementations of view layer integrations #63

Closed
stubailo opened this issue Mar 30, 2016 · 16 comments
Closed
Assignees
Milestone

Comments

@stubailo
Copy link
Contributor

Two to start with:

  1. ✅ React: https://github.com/apollostack/apollo-react
  2. Angular 2

Other candidates, to do as people need them:

  1. Blaze
  2. Riot.js
  3. Angular 1
  4. Ember
  5. Vue
@stubailo stubailo added this to the alpha milestone Mar 30, 2016
@stubailo stubailo added the idea label Mar 30, 2016
@mquandalle
Copy link
Contributor

A big 👍 for building that, we are getting closer to an Apollo MVP!

I wonder if it would be possible to customize the reactivity layer, for instance by using MobX + React, instead of Redux + React? Also there are some decisions to make on the API design, for instance I imagine that higher-order functions/components/decorators are much more recommendable these days than Tracker-like mixins.

@stubailo
Copy link
Contributor Author

I wonder if it would be possible to customize the reactivity layer, for instance by using MobX + React, instead of Redux + React?

I wonder if you have an idea for how this would work? At the end of the day, we need a state object that can be modified by firing actions. If MobX offers that, I imagine it wouldn't be hard to integrate. Also, what's the benefit here? Is it to integrate with some kind of MobX tooling?

Also there are some decisions to make on the API design, for instance I imagine that higher-order functions/components/decorators are much more recommendable these days than Tracker-like mixins.

I think each view layer's integration should be the best practice for that view layer. So for React it will be a container component similar to Relay, not sure what people do in Angular these days. In Blaze it would probably be some kind of Tracker-enabled function.

I already have a private demo app using the apollo client and React, and I built a trivial container that is used like this:

const TopicWithData = createContainer({
  getQuery: ({ params, loginToken }) => {
    const maybeLoginToken = loginToken ? `(token: "${loginToken}")` : '';

    return `
      {
        root${maybeLoginToken} {
          oneTopic(id: "${params.id}") {
            id
            category_id
            title
            posts {
              pages {
                posts {
                  username
                  score
                  cooked
                }
              }
            }
          }
        }
      }
    `;
  },
}, Topic);

This is probably the most basic thing we could build at first, if we don't want to dive into query aggregation and fragments and whatnot. (The code isn't open source yet because it's straight up just bad code, but we want to release this full-stack demo and a basic server this week or next)

@mquandalle
Copy link
Contributor

There have been a bit of discussion about MobX in apollographql/apollo#1. MobX basically does the same thing as Tracker, as it allow you to have some reactive data sources (in this case it could be a GraphQL query) and a reactive context that will be re-ran every time one of its dependency gets invalidated. With this model you are able to run arbitrary computation reactively (like with Tracker.autorun) including rendering React components. It allows a clear dependency graph and have various optimizations so that you can modify a bunch of data before flushing or register a dependency on only a subset of a reactive data source. By the way MobX has some good docs and introductions that give way better explanations that what I just wrote. You could also take a look at a MobX+React example written in Typescript here, and on MobX benefits more specifically, you might take a look at positive feedbacks it received on HN.

The point is that the update model is different if you use Redux (re-render the whole tree, probably use Immutable and implement a pure wrapper that generate the shouldComponentUpdate accordingly) or if you use MobX (where a reactive context can have some dependencies that generate a dependency tree/flow) and that’s something the Apollo view layer should take into account. So maybe one easy solution would be to have one apollo-react package that is basically the container that you demonstrated above and a completely separate package apollo-mobx that would transform Apollo queries into MobX observables and then we could use mobx-react as the actual view layer.

Not that this is super important in this early stage, but I just think it’s good to have in mind the various update models that people will want to use.

@stubailo
Copy link
Contributor Author

One of the core ideas I'm working with for this package is versioning the entire store as an immutable object, very much in the style of Redux. I think this is the most natural approach for a store which is normalized and shared between all queries, and immutable JS will hopefully let us determine relatively easily which parts of the query result have changed.

If this makes MobX integration a bit more work, for now that's just a cost we'll have to pay.

For what it's worth, I think most or maybe all people should be using this library via the view connector, and not by interacting with Redux or whatever directly. So we can make that layer do the work of determining if a particular query result actually changed or not, regardless of that Redux says.

@mquandalle
Copy link
Contributor

But one’s might as well want to perform some arbitrary computation using a Apollo/Graphql query as a data source, say for instance that you want to display an HTML5 notification when a new message is posted in a thread. How would that work if it is the view connector that is determining if a query result changed or not?

@stubailo
Copy link
Contributor Author

Sorry, I misspoke. It should be some layer between the Redux store and the view connector. So you could think of the MobX integration as a view connector.

@stubailo
Copy link
Contributor Author

And I agree that not firing spurious events on queries when their result didn't change should be a priority! Otherwise many things would become very hard to do and people would have to build custom result diffing, which kind of defeats the purpose.

@stubailo stubailo modified the milestone: alpha Apr 9, 2016
@stubailo stubailo self-assigned this Apr 13, 2016
@stubailo
Copy link
Contributor Author

Started a repo for React here: https://github.com/apollostack/apollo-react

Also, we're going to get going on Angular pretty soon.

@stubailo
Copy link
Contributor Author

Closing this issue in favor of having individual issues for each view layer.

#114 for Angular
#115 for React

@willemmulder
Copy link

willemmulder commented Apr 20, 2016

Riot.js would be awesome! 👍

@stubailo
Copy link
Contributor Author

Please open a new issue about it!

@praneybehl
Copy link

Would love to see support for Blaze 👍

@stubailo
Copy link
Contributor Author

Please open a new issue instead of commenting on a closed old one!

@smolinari
Copy link
Contributor

Would love to see vue-apollo come together. I'll be working on this myself as mentioned in the linked thread above.

Scott

@Akryum
Copy link

Akryum commented Sep 19, 2016

I got a vue integration running!

@stubailo
Copy link
Contributor Author

Wow, that's awesome!

jbaxleyiii pushed a commit that referenced this issue Oct 17, 2017
jbaxleyiii pushed a commit that referenced this issue Oct 18, 2017
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants