react-apollo

Is it possible to prevent `useLazyQuery` queries from being re-fetched on component state change / re-render?

送分小仙女□ 提交于 2020-01-22 14:52:09
问题 Currently I have a useLazyQuery hook which is fired on a button press (part of a search form). The hook behaves normally, and is only fired when the button is pressed. However, once I've fired it once, it's then fired every time the component re-renders (usually due to state changes). So if I search once, then edit the search fields, the results appear immediately, and I don't have to click on the search button again. Not the UI I want, and it causes an error if you delete the search text

Is it possible to prevent `useLazyQuery` queries from being re-fetched on component state change / re-render?

跟風遠走 提交于 2020-01-22 14:51:49
问题 Currently I have a useLazyQuery hook which is fired on a button press (part of a search form). The hook behaves normally, and is only fired when the button is pressed. However, once I've fired it once, it's then fired every time the component re-renders (usually due to state changes). So if I search once, then edit the search fields, the results appear immediately, and I don't have to click on the search button again. Not the UI I want, and it causes an error if you delete the search text

useLazyQuery causing too many re-renders [Apollo/ apollo/react hooks]

核能气质少年 提交于 2020-01-21 14:07:26
问题 I'm building a discord/slack clone. I have Channels, Messages and users. As soon as my Chat component loads, channels get fetched with useQuery hook from Apollo. By default when a users comes at the Chat component, he needs to click on a specific channels to see the info about the channel and also the messages. In the smaller Channel.js component I write the channelid of the clicked Channel to the apollo-cache. This works perfect, I use the useQuery hooks @client in the Messages.js component

Fetching query in method of a class component

Deadly 提交于 2020-01-16 19:49:11
问题 Apollo client (2.6.3) with react. Is it possible to fetch data in a method of a class component? I'm building a global search component and I want to fetch data only when 3rd (and each subsequent) character is typed. Right now it is implemented with fetch api but I want to switch to apollo client and graphql api. Until this moment I haven't gotten any problems with apollo client API cause I use <Query/> component. I've tried to use new hooks api but it turned out that useLazyQuery() can be

Cookies don't transfered in react and express.js

江枫思渺然 提交于 2020-01-16 08:46:54
问题 I have been working on project which backend uses express and apollo server and front end uses react js. Locally everything seems fine as server runs on port 2000 and react js runs on 3000. After building my react app I copied everything and place them server's public folder but after uploading them to remote server users can't authenticate since session id is not get transferred. Here is how I have configured base url in react app. App.js let BASE_URL = '' let WS_BASE_URL = '' let

refetchQueries in Mutation Component of React Apollo Client is not working?

我是研究僧i 提交于 2020-01-14 07:59:19
问题 I have a <Query /> in my Home.js file Home.js <Query query={GET_TODOS_BY_PRODUCT} variables={{ id: state.get("selectedProduct.id"), completed: true }} > {({ data: { product } }) => { return <Main todos={product.todos} hashtag={product.hashtag} />; }} </Query> In my Main.js file I have <Mutation /> component - Main.js <Mutation key={v4()} mutation={SWITCH_SELECTED_PRODUCT} refetchQueries={() => { console.log("refetchQueries", product.id); return { query: GET_TODOS_BY_PRODUCT, variables: { id:

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

白昼怎懂夜的黑 提交于 2020-01-14 05:08:06
问题 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 } = useQuery(QUERY, { onBeforeDataGoesToCache: originalResponseData => { // modify data before it is cached? Can I have something like this? return modifiedData; } }); Obviously onBeforeDataGoesToCache does not exist, but that's exactly the behavior I

React Apollo 2 with React Router. graphql HOC loading: true forever if I navigate

微笑、不失礼 提交于 2020-01-13 13:11:28
问题 This is the code: https://codesandbox.io/s/p90q6674qq I simply use: export default graphql(CURRENT_USER_QUERY)(Menu); on the Menu component and simply this code in App component: class App extends Component { render() { return ( <div> {/* <Menu /> */} <Route component={Menu} /> <Route exact path="/" component={Home} /> <Route path="/login" component={Login} /> </div> ); } } A bug? Where am I wrong? 来源: https://stackoverflow.com/questions/47733633/react-apollo-2-with-react-router-graphql-hoc

React Apollo 2 with React Router. graphql HOC loading: true forever if I navigate

久未见 提交于 2020-01-13 13:10:09
问题 This is the code: https://codesandbox.io/s/p90q6674qq I simply use: export default graphql(CURRENT_USER_QUERY)(Menu); on the Menu component and simply this code in App component: class App extends Component { render() { return ( <div> {/* <Menu /> */} <Route component={Menu} /> <Route exact path="/" component={Home} /> <Route path="/login" component={Login} /> </div> ); } } A bug? Where am I wrong? 来源: https://stackoverflow.com/questions/47733633/react-apollo-2-with-react-router-graphql-hoc

How to wrap GraphQL mutation in Apollo client mutation component in React

落花浮王杯 提交于 2020-01-06 07:23:10
问题 I am having an issue wrapping the Apollo mutation component along with the query component. If you look at the updateCell function I am able to get the oldValue, newValue, and ID for the row. How can I pass the values to ADDCOST mutation using Apollo client mutation component. Below is my code: Thanks in advance for any tips. const APPROVALCHAIN_QUERY = gql` { vApprovalChainApproverCountList{ applicationId applicationName collectionName licenseType cost approvers } } `; const ADDCOST_MUTATION