1.2.0 ā€¢ Published 1 year ago

@habx/apollo-refetch v1.2.0

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

Utils for apollo queries refetching

CircleCI Version Size License

Motivation

Displaying lists with apollo client is really common but it can be very hard to update theses lists with new data or retrieve data from it. We wanted to be able to display data that is always server-sync even if the list has parameters.

Install

npm i @habx/apollo-refetch

Wrap your App with the context provider

  <RefetchProvider>
    {children}
  </RefetchProvider>

How to use

First register your query

 const { refetch, ... } = useQuery<contacts, contactsVariables>(contactsQuery, {
    variables: {
      filters: state.filters,
      paginate: state.paginate,
      orderBy: state.orderBy,
    },
  })
  useRegisterRefetch('contacts', refetch)

Then when you add, remove an element

  const { refetch } = useRefetch()
  const [handleUpsertContact] = useMutation<
    upsertContact,
    upsertContactVariabes
  >(upsertContactMutation, { onCompleted: () => refetch('users')})

And you're done šŸ‘

āš ļø It's not useful to use useRefetch when the operation is an update of an existing entity, apollo updates it automatically

1.2.0

1 year ago

1.1.0

2 years ago

1.0.0

2 years ago

0.5.0

2 years ago

0.6.0

2 years ago

0.5.1

2 years ago

0.4.0

3 years ago

0.3.0

4 years ago

0.2.0

4 years ago

0.1.0

4 years ago