Code Monkey home page Code Monkey logo

apollo-live-client's People

Contributors

theodordiaconu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

apollo-live-client's Issues

Field "doc" must not have a selection since type "JSON" has no subfields.

So I am very new to Apollo/GraphQL in general, so please bear with me:

const GET_USERS = gql`
  query($limit: Int, $skip: Int) {
    lists(limit: $limit, skip: $skip) {
      _id
      list_id
      row_id
    }
  }
`

const SUBSCRIBE_USERS = gql`
  subscription($limit: Int, $skip: Int) {
    lists(limit: $limit, skip: $skip) {
      event
      doc {
        _id
        list_id
        row_id
      }
    }
  }
`

My :

<ReactiveQuery
  query={GET_USERS}
  variables={{limit: 20, skip: (page-1)*20}}
  subscription={SUBSCRIBE_USERS}
>
  {
    ({ loading, error, data }) => {
      if(loading) return <h2>loading</h2>
      if(error) {
        console.log(error)
        return <h2>Error</h2>
      }                
      let { lists } = data;
      console.log(lists);                
      return 'loaded'
    }
  }
</ReactiveQuery>

my typeDefs on the server look something like this:

type Query {
  lists(limit: Int, skip: Int): [List]
  list(id: Int): List
}

type List @mongo(name: "listsbody") {
  _id: ID
  list_id: ID
  row_id: Int
}

type Item @mongo(name: "items") {
  _id: ID
  created_at: String
  supplier_id: ID
}

type Subscription {
  lists(limit: Int, skip: Int): SubscriptionEvent
}

... any my Subscription resolver:

Subscription: {
  lists: {
    resolve: payload => payload,
    subscribe(_, {limit, skip}, { db }, ast) {
      const observer = db.listsbody.astToQuery(ast, {
        $options: { limit, skip }
      });
      // const observer = db.listsbody.find({}, { limit: 100 });
      return asyncIterator(observer);
    }
  }
}

After some time always the same Error pops up:

Field "doc" must not have a selection since type "JSON" has no subfields.

I guess I am missing something here I just can't see right now with my not existing GraphQL experience. 😄 Hope someone can help, thanks!

Add the ability to specify the fetchPolicy for the Query in the <ReactiveQuery> component

I find that if I have fetched the query already and then close the subscription (navigate away from the page) and anything is changed while I am gone and then I come back the initial load will pull from the cache and be out of sync. I think that would be fixed just by changing the fetchPolicy to “cache-and-network” but I looked at your component and it looks like you’re only passing the query and variables to the react-apollo component.

Changing variables does not update subscription

Hi there,

I (think I) made quite some progress in understanding/using Apollo/GraphQL/Subscriptions but I now ran into the following problem:

Say I have a React component using your <ReactiveQuery/> which has some variables passed as prop. Problem is, that due to you only using componentDidMount() (https://github.com/cult-of-coders/apollo-live-client/blob/master/src/ReactiveQuery.js#L37), (maybe instead of componentDidUpdate()), the subscription is not updated when the variables change.

I do not understand how this should work like that ...

best regards, Patrick

withTracker() HOC breaks Subscription

Original Issue: Swydo/ddp-apollo#354

Following setup:

I have a parent React component (<TestPage/>) which uses the standard withTracker() HOC to load some stuff from normal Meteor subscriptions.
The wrapper <TestPage/> then uses a standard logic in its render function like so: if(this.props.loading) return <Loading/>; // ... return <ReactiveQuery .../>

I wrote myself a little DDP message debugger based on this: https://stackoverflow.com/questions/25373648/how-to-view-meteor-ddp-traffic

Using this I can monitor subs and unsubs.

Following problem:
If the <Parent/> displays <Loading/> at least once before displaying the actual <ReactiveQuery .../> the subscription is immediately canceled again after subbing!

When I remove the if(this.props.loading) return <Loading/>; the subscription works just fine, although I have more (re-) renders obviously.

The problem is, that I can NOT simply remove if(this.props.loading) return <Loading/>; in my actual production app, since there are many more child components depending on the data loaded inside the withTracker() HOC. These are broken after remove the if(loading).

Anyone ever experienced this? I just don't understand what exactly is causing this behavior, but this is completely breaking my app because I really need this subscriptions to work!

<TestPage/>

class TestPage extends React.Component {
  render() {
    const { currentUser } = this.props.store.current;
    const { loading } = this.props;
    if(loading) return <Loading/> // this line breaks the Subscription!
    return (
      <div className="container">
        <TestItemlist type="list" listId="YBxgJgkSNLHBmdNpp" openOrderId="jFZJm79tSQYuhqpna" />
      </div>
    )
  }
}

export default withTracker((props) => {
  const groupId = "7gLtWKifiRtEAeTvq";
  const sub1 = Meteor.subscribe('buyer:getGroups');
  const sub2 = Meteor.subscribe('group:getOpenOrderHead', groupId);
  const sub3 = Meteor.subscribe('group:getLists', groupId);
  const loading = !sub1.ready() || !sub2.ready() || !sub3.ready();
  const group = Groups.findOne({ _id: groupId });
  if(!group || loading) return { loading: true }
  const supplier = Meteor.users.findOne({ _id: group.supplierId });
  return {
    loading,
    group,
    supplier,
    lists: ListsHead.find({ groupIds: groupId, 'special': { $nin: ['blacklist'] } }, { sort: { datetime: -1 } }).fetch(),
    currentOpenOrder: OpenOrdersHead.findOne({ group_id: groupId })
  }
})(withMainStore(TestPage))

<TestItemlist/>

export default class TestItemlist extends React.PureComponent {
  constructor() {
    super();
    this.state = {
      page: 1
    }
  }
  prevPage = () => {
    this.setState(state => {
      if(state.page == 1) return;
      state.page--;
      return state;
    });
  }
  nextPage = () => {
    this.setState(state => {
      state.page++;
      return state;
    });
  }
  render() {
    let query = GET_LIST_DATA;
    let subscription = SUB_LIST_DATA;
    let variables = { listId: this.props.listId, limit: 20, skip: (this.state.page-1)*20 };
    const { type } = this.props;
    if(type == 'cart') {
      query = GET_CART_DATA;
      subscription = SUB_CART_DATA;
      variables = { openOrderId: this.props.openOrderId };
    }
    return (
      <ReactiveQuery
        query={query}
        subscription={subscription}
        variables={variables}
      >
        {(props) => {
          const { data, error, loading, refetch } = props;
            return ...
          )
        }}
      </ReactiveQuery>
    )
  }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.