react-apollo

updateQueries after GraphQL mutation not working with the Apollo client

旧巷老猫 提交于 2019-12-01 20:25:51
After I'm sending a createMessage mutation in my app, I want to update the local ApolloStore using updateQueries . My setup looks as follows: const ChatWithAllMessages = graphql(allMessages, {name: 'allMessagesQuery'})(Chat) export default graphql(createMessage, { props({ownProps, mutate}) { return { createMessageMutation(text, conversationId) { return mutate({ variables: { text, conversationId }, updateQueries: { allConversations: (previousState, {mutationResult}) => { console.log('Chat - did send mutation for allConversationsQuery: ', previousState, mutationResult) return ... } } }) } } } })

Apollo Client Write Query Not Updating UI

試著忘記壹切 提交于 2019-12-01 09:17:37
We are building an offline first React Native Application with Apollo Client. Currently I am trying to update the Apollo Cache directly when offline to update the UI optimistically. Since we offline we do not attempt to fire the mutation until connect is "Online" but would like the UI to reflect these changes prior to the mutation being fired while still offline. We are using the readQuery / writeQuery API functions from http://dev.apollodata.com/core/read-and-write.html#writequery-and-writefragment . and are able to view the cache being updated via Reacotron, however, the UI does not update

How to chain together Mutations in apollo client

柔情痞子 提交于 2019-11-30 23:08:46
I have a bunch of information stored in my state that I need to pass to my graphQL server using mutations, but I need to use the results of each mutation before I call the next one since I need to: Create a new object in my database Use the id generated for that object to create another object Modify the original object to store the id generated by the second object I noticed that apollo Mutation components have an onCompleted callback, but I don't know how to use this callback to fire off another mutation or whether it's the right way solve my problem. I also looked into batching my mutations

React-apollo update vs refetch

谁都会走 提交于 2019-11-30 19:54:19
问题 I am using react-apollo and have been for quite some time. One thing that has already been a problem for me is the fact that refetch doesn't work when using a mutation This has been a know issue for as long as I have been using the app. I have got round this by using the refetch prop that is available on a query. <Query query={query} fetchPolicy={fetchPolicy} {...props}> {({ loading, data, error, refetch }) => { ... pass down to mutation </Query> However I am now reading in the documentation

How to execute an async fetch request and then retry last failed request?

巧了我就是萌 提交于 2019-11-30 02:19:22
Apollo link offers an error handler onError Issue: Currently, we wish to refresh oauth tokens when they expires during an apollo call and we are unable to execute an async fetch request inside the onError properly. Code: initApolloClient.js import { ApolloClient } from 'apollo-client'; import { onError } from 'apollo-link-error'; import { ApolloLink, fromPromise } from 'apollo-link'; //Define Http link const httpLink = new createHttpLink({ uri: '/my-graphql-endpoint', credentials: 'include' }); //Add on error handler for apollo link return new ApolloClient({ link: ApolloLink.from([ onError(({

How to run a mutation on mount with React Apollo 2.1's Mutation component?

只愿长相守 提交于 2019-11-29 07:34:44
问题 We are currently moving from Relay to React Apollo 2.1 and something I'm doing seems fishy. Context: Some components must only be rendered if the user is authenticated (via an API key), so there is an Authenticator component guarding the rest of the tree. In App.js , it gets used like this (obviously all snippets below are minimal examples): import React from 'react'; import Authenticator from './Authenticator'; import MyComponent from './MyComponent'; export default function App({ apiKey })

Setting state in the Query component of react-apollo

混江龙づ霸主 提交于 2019-11-29 06:12:49
问题 So, I'm trying to set an initial state for an edit component that gets data from the server and now should be editable in the component state. But when I try to do this: <Query query={POST_QUERY} variables={{ id: this.props.match.params.id }}> {({ data, loading, error }) => { this.setState({ title: data.title }) I get stuck in an infinite loop since this is in render. Should I not use the component state with the query component? And if not, what is the alternative? 回答1: Whatever component

How to execute an async fetch request and then retry last failed request?

左心房为你撑大大i 提交于 2019-11-28 23:00:19
问题 Apollo link offers an error handler onError Issue: Currently, we wish to refresh oauth tokens when they expires during an apollo call and we are unable to execute an async fetch request inside the onError properly. Code: initApolloClient.js import { ApolloClient } from 'apollo-client'; import { onError } from 'apollo-link-error'; import { ApolloLink, fromPromise } from 'apollo-link'; //Define Http link const httpLink = new createHttpLink({ uri: '/my-graphql-endpoint', credentials: 'include' }

How to chain two GraphQL queries in sequence using Apollo Client

£可爱£侵袭症+ 提交于 2019-11-26 14:00:10
问题 I am using Apollo Client for the frontend and Graphcool for the backend. There are two queries firstQuery and secondQuery that I want them to be called in sequence when the page opens. Here is the sample code (the definition of TestPage component is not listed here): export default compose( graphql(firstQuery, { name: 'firstQuery' }), graphql(secondQuery, { name: 'secondQuery' , options: (ownProps) => ({ variables: { var1: *getValueFromFirstQuery* } }) }) )(withRouter(TestPage)) I need to get