aruntk / polymer-apollo

🚀 Polymer Apollo Integration
MIT License
78 stars 7 forks source link

Refresh a query #2

Closed atoy40 closed 7 years ago

atoy40 commented 7 years ago

Hello,

i've a polymer element with the PolymerApolloBehavior, and want to know if it's possible to "refresh" a query result either through code (calling a function on $apollo ?) or through a polymer binding ? My query has no variable so I cannot use your "observers" mechanisme on variables and I don't want to use polling.

Thks Anthony.

atoy40 commented 7 years ago

I think this can work :

this._apolloObservers[0].observer.refetch()

But may be it can be a good idea to have a function to get observers from "key" name ? What do you think about ?

aruntk commented 7 years ago

@atoy40 Great suggestion. I'll implement this.$apollo.refetch(key); function to refetch the query.

atoy40 commented 7 years ago

@aruntk May be another idea with the same goal, for each query, it could be nice to set an array of "dependencies" (property paths) which can fire a refetch when changed (like you did with graphql variables)

btw, if we've an easy function, it's maybe better to create a polymer observer on theses properties and call the refetch.

aruntk commented 7 years ago

@atoy40 Hi. I've added a refetch function to $apollo. Call it as this.$apollo.refetch(key);

atoy40 commented 7 years ago
    visibilityChanged: function(visible) {
        if (visible) {
          this.async(function() {
            if (this.loadingDisks === false) {
              this.$apollo.refetch("disks");
            }
          });
        }
      },

is working. Thks