parse-community / ParseReact

Seamlessly bring Parse data into your React applications.
https://parseplatform.org
Other
1.3k stars 209 forks source link

Unable to retrieve data from parse #174

Open BrunoAl opened 8 years ago

BrunoAl commented 8 years ago

Hello, I am using parse as my app back-end, but I am unable to receive data with the observe() method, although I'm sure that react is properly connect with parse because I can mutate data with the ParseReact.mutation.

import React from 'react';
import Parse from 'parse';
import ParseReact from 'parse-react';

const pinRegister = React.createClass({
  mixins: [ParseReact.Mixin],

  observe() {
    return {
      pins: (new Parse.Query('Pin'))
  },
  render() {
    return {
      <ul>
       {this.data.pins.map(function(pin) {
        return <li>{pin}</li>;
       })}
      </ul>
    }
  }        
});

On the console I receive this message: "WebSocket connection to 'ws://mywsaddress:8080/parse' failed: Connection closed before receiving a handshake response" and the this.data.pins gets undefined,I checked the data in parse-dashboard and the Pin class is has the properly data.

moflo commented 8 years ago

Hi, seeing this same issue when running a Parse server on Heroku. Thought it was a problem with their latest stack, but it seems they fully support WS now. Any suggestions?

BrunoAl commented 8 years ago

Yes, I realized that I was missing the liveQuery on my node server, I included it and the socket error stopped.

var api = new ParseServer({
  ...

  liveQuery: {
    classNames: ['Pin']
  }
});

But now now I'm still unable to receive data, on chrome's console I get this: Uncaught TypeError: this._subscriptions[name].dispose is not a function, and this problem comes from this peace of code from parse-react:

_unsubscribe: function _unsubscribe() {
    for (var name in this._subscriptions) {
      this._subscriptions[name].dispose();
    }
    this._subscriptions = {};
  },
moflo commented 8 years ago

I too missed that LiveQuery was a requirement (!) and am now also able to POST but not receive any data via web sockets / LiveQuery observe methods. FWIW, I'm using the following:

  "parse": "~1.8.3",
  "parse-server": "~2.2.7"
  "parse-react": "^0.5.1",
BrunoAl commented 8 years ago

Anyone have any idea of how to solve this? It's a major issue, and it looks like nobody is talking about this on the web. On my development team, the android dev had no problem with parse using the exactly same nodejs server, so it must be something wrong on parse-react.

dcalogue commented 8 years ago

Could you try the following? Add the following logs to the ParsePatches.js file

var ParsePatches = {
  applyPatches: function applyPatches() {
    console.log("Applying parse react patches");
    if (!Parse.Object.prototype.toPlainObject) {
      Parse.Object.prototype.toPlainObject = patches.toPlainObject;
    }
    if (!Parse.Query.prototype.subscribe) {
      console.log("Applying subscribe to Query");
      Parse.Query.prototype.subscribe = patches.subscribe;
    }
    if (!Parse.Query.prototype.observeOne) {
      Parse.Query.prototype.observeOne = patches.observeOne;
    }

It seems that someone introduced a subscribe function into the Parse code, which breaks the Parse patch from ParseReact (if you want both ParseReact and liveQuery you should change all references to subscribe in the ParseReact code to another function name).

Let me know if this fixes your problem (I had a similar problem and had to dive into the code to find what was going on)

BrunoAl commented 8 years ago

@dcalogue I think you are right! I was too lazy to change all the references of subscribe, so I did this just to give it a shot:

var ParsePatches = {
  applyPatches: function applyPatches() {
    console.log("Applying parse react patches");
    if (!Parse.Object.prototype.toPlainObject) {
      Parse.Object.prototype.toPlainObject = patches.toPlainObject;
    }
    if (true) {
      console.log("Applying subscribe to Query");
      Parse.Query.prototype.subscribe = patches.subscribe;
    }
    if (!Parse.Query.prototype.observeOne) {
      Parse.Query.prototype.observeOne = patches.observeOne;
    }

And it worked! Thank you very much.

dcalogue commented 8 years ago

That's what I did too, but be warned that we are overwriting a Parse function (not only adding a new one, which was what the Patch did before), so some functionality may be missing (I think the function we are overriding is related to the new liveQuery functionality)

BrunoAl commented 8 years ago

Someone should really fix this for the next ParseReact release.

paulods commented 8 years ago

Is anyone still working on the next ParseReact release?

haydenbleasel commented 7 years ago

You can install an earlier version of Parse. I went back to parse@1.6.14, which has fixed it.

freeznet commented 7 years ago

@haydenbleasel parse@1.6.14 solved this problem but without LiveQuery supporting