apollo-client

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

Why is refetchQueries needed?

♀尐吖头ヾ 提交于 2020-01-16 08:41:15
问题 I am following a tutorial on GraphQL, in the video the author does not use refetchQueries for a deleteMutation and all works well with UI updates and mutation. But here in the project sandbox code is updated and refetchQuery is now used for this operatio on Job component -> line 20 -> deleteJob(): codeSandBox. I have this similar problem in my app that does not update the UI automatically without refetchQueries done everywhere. Shouldn't Apollo be applying automatically the cache of Apollo

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

How to call a GraphQL query/mutation from an Express server backend?

别等时光非礼了梦想. 提交于 2019-12-30 03:12:42
问题 My frontend is localhost:3000 , and my GraphQL server is localhost:3333 . I've used react-apollo to query/mutate in JSX land, but haven't made a query/mutation from Express yet. I'd like to make the query/mutation here in my server.js . server.get('/auth/github/callback', (req, res) => { // send GraphQL mutation to add new user }); Below seems like the right direction, but I'm getting TypeError: ApolloClient is not a constructor : const express = require('express'); const next = require('next