Questions tagged [react-apollo-hooks]

89 questions
4
votes
1 answer

Apollo useLazyQuery repeatedly called

I'm trying to build a form that could be used for any CRUD operation on a table. For the update operation I'd like to pass the variable with the route. All of that is working fine but when I call the query using a lazy query it does nothing for the…
Ben Riga
  • 904
  • 1
  • 9
  • 16
4
votes
1 answer

React Apollo Client - modify query data before it goes to cache

Is there a way to modify query response data before it is saved in the internal cache? I'm using apollo hooks, but this question is relevant to any of front-end approaches using apollo client (HOC & Components as well). const { data, updateQuery }…
4
votes
5 answers

how to use useMutation or useQuery as hook on React or React Native?

That's the exception that I got..and it's does not make sense for me... Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons: 1. You might have mismatching…
Marco Jr
  • 6,496
  • 11
  • 47
  • 86
4
votes
0 answers

Apollo react useQuery cache working strange

I have a component with a data list. Also, I have another with mutation for item element. After the update, cached is updated, but list stays not update until rerender component. List component query: export const categoriesQuery = gql` query…
Edgaras Karka
  • 7,400
  • 15
  • 61
  • 115
3
votes
1 answer

Apollo Client: writeFragment or readFragment when updating cache?

In the update hook of useMutation, Apollo's documentation recommends using writeFragment to get an internal reference to a newly added object. I find this peculiar, as that object already exists in the cache. So I tested it with readFragment and…
Johnny Oshika
  • 54,741
  • 40
  • 181
  • 275
3
votes
1 answer

Call another query onComplete of one query in apollo client using react native

I am getting invalid hook call for nested queries const fetchNotifications = useNotificationsQuery({ variables: { skip: SKIP, take: TAKE, }, async onCompleted(data){ let…
3
votes
2 answers

`data` is undefined in apollo useMutation Promise

Why is data undefined in Promise even though it appears in html below? I dont want to use .then((data) => const LoginPage: React.SFC<{}> = () => { const [login, { loading, data, error }] = useMutation(MUTATION) const onSubmit = event…
AHOYAHOY
  • 1,856
  • 4
  • 24
  • 34
3
votes
2 answers

Rendered more hooks than during the previous render

How to use 2 graphql queries with react-apollo-hooks where the 2nd query depends on a parameter retrieved from the 1st query? I try to use 2 queries which looks like this: const [o, setO] = useState() const { loading: loadingO, error: errorO, data:…
microman
  • 141
  • 2
  • 12
3
votes
2 answers

How do you use useMutation from react-apollo-hook to execute a delete mutation?

I'm trying to use the useMutation hook from react-apollo-hooks to execute a delete mutation, but I'm having difficulty passing the ID value of the post to the mutation hook in the following code: const Posts = () => { const { data, error,…
Kevvv
  • 3,655
  • 10
  • 44
  • 90
2
votes
0 answers

Apollo MockedProvider Immediately Returns Null

I am troubleshooting a failing React unit test that uses TestRenderer from react-test-renderer. My component queries a rest endpoint using GraphQL via the useQuery hook. If I wrap my component with and call .toJSON(), it immediately…
2
votes
0 answers

Apollo client useQuery makes additional call with the first page on every fetchMore call

There is a pagination example on the https://www.apollographql.com/docs/react/pagination/offset-based/. Given there is a peace of code: const { loading, data, fetchMore } = useQuery(FEED_QUERY, { variables: { offset: 0, limit: 10, …
2
votes
0 answers

Polling the `useQuery` causes un-necessary re-renders in React component

I have a hook that looks like this export const useThing = id => { const { stopPolling, startPolling, ...result } = useQuery(GET_THING, { fetchPolicy: 'cache-and-network', variables: { id }, skip: !id }); return…
2
votes
2 answers

Fetch more function is undefined for useLazyQuery react-apollo hook

I use react-apollo useLazyQuery hook. My goal to use it in fetch more button click. However, when I try to use it the fetchMore function is undefined. Here the call to it: const [getMyData,{ loading, data, fetchMore }] = useLazyQuery( myQuery, …
AlexBerd
  • 1,368
  • 2
  • 18
  • 39
2
votes
0 answers

Partial cached values in apollo/graphql

Let's say I have a schema like this (pseudocode) query comments: [Comment] query comment(id: Int!): Comment And I'm fetching comments like this (pseudocode) comments { id text } comment { id text author { id name } } In my components…
CaptainStiggz
  • 1,787
  • 6
  • 26
  • 50
2
votes
0 answers

Resending a graphql mutation after re-authenticating using Apollo's useMutation

I have an issue where we're using apollo client and specifically the useMutation react hook to perform mutation calls to our GraphQL Server. At certain times, the server may return a 401 unauthorized response - at which point, we can make a call to…