Apollo React - `useMutation` in ApolloClient setup?

后端 未结 1 373
别跟我提以往
别跟我提以往 2021-01-28 05:00

I have an interesting situation.

I want to initiate refresh token request USING Apollo itself (a.k.a to call a mutation)

Any idea, how to achieve something like

相关标签:
1条回答
  • 2021-01-28 05:43

    You can't use a hook outside a functional React component. You can use the client directly to make queries and mutations -- just bear in mind that any queries ran this way will not be observable (i.e. won't be updated if the cache changes).

    const client = new ApolloClient({
      link: ApolloLink.from([
        onError(({ graphQLErrors, networkError, operation, forward }) => {
          client.mutate({ mutation, variables })
            .then(({ data }) => {
              console.log(data)
            })
            .catch((error) => {
              console.log(error)
            })
        }),
        new HttpLink({...}),
      ]),
    })
    
    export default client
    
    0 讨论(0)
提交回复
热议问题