1.0.7 • Published 6 years ago

apollo-hooks-refetch v1.0.7

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

React Apollo Hooks (with refetch support)

This package is deprecated, use the official apollo/react-hooks package instead. The interface is the same as this one with extended functionality

Install

npm i apollo-hooks-refetch

useQuery

QUERY_RESULT = useQuery(QUERY, QUERY_OPTIONS)

const queryResult = useQuery(gql`
  query List($filterByName: String) {
    List(filterByName: $filterByName) {
      id
    }
  }
`, {
  variables: { filterByName }
})

useMutation QuickSample

[MUTATOR, MUTATION_RESULT] = useMutation(MUTATION, MUTATION_OPTIONS)

const [mutate, mutationResult] = useMutation(gql`
  mutation addListItem($item: JSON) {
    addListItem(item: $item) {
      id
    }
  }
`, {
  variables: { item }
})

<Button onPress={() => if (!mutationResult.loading) mutate()} />

MUTATOR is a promise that will resolve with an object that contains canceled if the parent component is dismounted. This makes mutations resilient to dismounts but does not actually cancel the mutation if the server is acting on it. A response from the server on a canceled mutation will still be caught by the apollo client and all cache resolvers will work as intended.

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago