Skip to content

Conversation

@kamilkisiela
Copy link
Member

@kamilkisiela kamilkisiela commented Jun 1, 2016

An example of usage:

this.exampleMutation(options)
  .then((graphQLResult) => {
    this.exampleQuery.refetch();
  });

UPDATE - see that comment


Outdated now

<li *ngFor="let example of exampleQuery | apolloQuery:'examples'">
  {{ example.description }}
</li>

@kamilkisiela
Copy link
Member Author

@jboothe So here's an idea you're interested in :)

@kamilkisiela
Copy link
Member Author

kamilkisiela commented Jun 15, 2016

While I was working on GitHunt for Angular2 I added few new features.

@stubailo You might be interested in the progress 🚀

@Urigo There are still no tests for that features so for now it's just a sort of concept rather then "ready to go" thing.

So what's new?

  • Apollo decorator is now able to handle or to be more precise, gives an access to few queries inside a one root query.
  • options of mapped queries are now the same as in ApolloClient's watchQuery method (forceFetch, returnPartialData and pollInterval)
  • refetch() is now supported
  • unsubscribe() is also available
  • stopPolling() is done
  • startPolling() too
  • loading - boolean property with loading status

Result of a query:

{
  loading: boolean
  errors: any[]
  refetch: Function
  unsubscribe: Function
  stopPolling: Function
  startPolling: Function
  ...
  [string]: any // query name as a key and result of that query as value 
  // (an example: `feed`: [{id: 1}, {id: 3}, {id: 5}])
}

An example:

@Component({
  selector: 'app',
  templateUrl: '/app.html'
})
@Apollo({
  client,
  queries(context) {
    return {
      data:  {
        query: gql`
          query Feed($type: FeedType!) {
            currentUser {
              login
            }
            feed(type: $type) {
              createdAt
              id
            }
          }
        `,
        variables: {
          type: context.type ? context.type.toUpperCase() : 'TOP'
        },
        forceFetch: true,
      }
    };
  }
})
class App {}
<loading *ngIf="data.loading"></loading>
<feed-entry
  *ngIf="!data.loading" 
  *ngFor="let entry of data.feed" 
  [entry]="entry"
  [currentUser]="data.currentUser"
  (onVote)="onVote($event)">
</feed-entry>

@kamilkisiela
Copy link
Member Author

And a working implementation of it (one issue with additional record in ngFor, but that's all) https://github.com/kamilkisiela/GitHunt-angular2/commit/a0593e4afb8c8bb402cb0f04ab26b4437b3a1017

@kamilkisiela kamilkisiela changed the title [Work in Progress] Concept of refetching data and droping AsyncPipe Concept of refetching data and droping AsyncPipe Jun 15, 2016
Kamil Kisiela added 9 commits June 15, 2016 20:06
What is new? Mostly the return value of mapped query

It now contains:

* errors - of subsription

* loading - boolean with status

* unsubscribe - just like the result of watchQuery

* refetch

* stopPolling

* startPolling

forceFetch, returnPartialData and pollInterval have been added to mapped queries options which are now exactly the same as watchQuery options
@kamilkisiela kamilkisiela changed the title Concept of refetching data and droping AsyncPipe Refetch, polling, loading, basically all Jun 15, 2016
@kamilkisiela
Copy link
Member Author

After releasing this, GitHunt for Angular2 will be practically ready.

@Urigo Urigo merged commit 88da3b8 into the-guild-org:master Jun 15, 2016
@helfer
Copy link
Contributor

helfer commented Jun 15, 2016

Thanks a lot! @kamilkisiela

@kamilkisiela kamilkisiela deleted the manual-async branch June 15, 2016 19:42
@kamilkisiela
Copy link
Member Author

@helfer It's always a pleasure to help!

kamilkisiela pushed a commit to kamilkisiela/docs that referenced this pull request Jun 15, 2016
kamilkisiela pushed a commit to kamilkisiela/docs that referenced this pull request Jun 15, 2016
kamilkisiela pushed a commit to kamilkisiela/docs that referenced this pull request Jun 16, 2016
kamilkisiela pushed a commit to kamilkisiela/docs that referenced this pull request Jun 16, 2016
jbaxleyiii pushed a commit to apollographql/apollo-client that referenced this pull request Oct 17, 2017
jbaxleyiii pushed a commit that referenced this pull request Oct 18, 2017
Update usage of networkInterface for latest apollo-client
it-efrem pushed a commit to it-efrem/Apollo-Angular that referenced this pull request Mar 14, 2020
it-efrem added a commit to it-efrem/Apollo-Angular that referenced this pull request Mar 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants