Files
apollo/docs/api/smart-subscription.md
T
Andy Ghiuta 78749c982d feat: Send the query key as argument to the skip fn (#810)
* Send the query key as argument to the skip fn

This enabled the possibility for the skip to be defined in defaultOptions
And based on certain things from the query to skip it
EG: query with variable X should be skiped  until Y prop is available

* fix: watch logic

* docs(api): skip option

* chore: fix e2e dev

* fix: skip watch logic
2019-10-19 15:34:54 +02:00

1.3 KiB

Smart Subscription

Each subscription declared in the apollo.$subscribe option in a component results in the creation of a smart subscription object.

Options

  • query: GraphQL document (can be a file or a gql string).
  • variables: Object or reactive function that returns an object. Each key will be mapped with a '$' in the GraphQL document, for example foo will become $foo.
  • throttle: throttle variables updates (in ms).
  • debounce: debounce variables updates (in ms).
  • result(data, key) is a hook called when a result is received
  • error(error) is a hook called when there are errors. error is an Apollo error object with either a graphQLErrors property or a networkError property.
  • skip is a boolean or a (reactive) function that returns a boolean. The function gets the current component and smart query key as arguments, so it can be used in $query and in ApolloProvider's defaultOptions.

Properties

Skip

You can pause or unpause with skip:

this.$apollo.subscriptions.users.skip = true

Methods

refresh

Stops and restarts the query:

this.$apollo.subscriptions.users.refresh()

start

Starts the query:

this.$apollo.subscriptions.users.start()

stop

Stops the query:

this.$apollo.subscriptions.users.stop()