apollo-client

How to use this.state.rent value instead of this.props.house.rent value in cache.readQuery or cache.writeQuery

丶灬走出姿态 提交于 2019-12-11 19:13:27
问题 The old value comes back into the input field. I had initialized this.props.house.rent (which is the old value coming back) with input field value this.state.rent (user entered value) but I cannot do it as it becomes antipattern syntax, you can see it in below comments of code. cacheUpdate = (cache, { data: { updateHouse } }) => { const data = cache.readQuery({ query: QUERY_CONFIRM_QUERY, variables: { id: this.props.confirmId }, }); const houses = data.queryConfirm.houses; const prevHouse =

Does the Apollo client cache nested objects in React?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 18:39:33
问题 Take the following queries: query Foo { foo { id bar(id: 1) { id baz } } } query Bar { bar(id: 1) { id baz } } Sometimes, running the 2nd query gets me a cached version of bar . Other times, it doesn't, but I'm not sure if this is because the query is run multiples times or because that's the default behaviour of the Apollo client in React. 回答1: No, it doesn't (as of Nov 2019, at least). To put the bar object in the cache when running the Foo query, you need to create the in-memory cache like

apollo-link-state defaults derived from query data?

可紊 提交于 2019-12-11 12:59:23
问题 Note: This is a followup question to my previous question about Apollo GraphQl Storing derived data I'm using apollo-link-state to store data that's derived from query data. In this example the query data from the db includes some (x,y) points on a graph and the derived data is slope, moving average, acceleration etc. My React graphing components need different combinations of original and derived data. Some need only the original. I need derived data to be calculated only once and only when

Querying and Mutating a Form with Apollo Client GraphQL

被刻印的时光 ゝ 提交于 2019-12-11 10:39:00
问题 The whole GraphQL paradigm is new to me, usually working with React Redux. My requirements are: User clicks a Row Item w/ UID We open a form to edit this data (with previously saved information pre-populated) We then edit this data and save I would think (2) & (3) would be handled by a <Query><Mutation/><Query> type of structure but it doesn't work, mainly because setting state in the Query will make the textinputs controlled inputs... controlled by <Query> , and I can no longer edit it.

Why do we need `cacheRedirects` at all?

给你一囗甜甜゛ 提交于 2019-12-11 08:15:05
问题 I read the docs on interacting with cached data and while I understand how cacheRedirects works, I'm a bit confused why it is needed in the first place. This is part of the reason why I asked this other question: Does the Apollo client cache nested objects in React? We know that the data is most likely already in the client cache, but because it's requested with a different query, Apollo Client doesn't know that. Why is that? Copy-pasting the example in the docs, for clarity: query ListView {

Apollo can't access queryVariables in update: after a mutation

独自空忆成欢 提交于 2019-12-11 07:36:14
问题 I am trying to use update: to update a query after performing a mutation. The problem is that the query in the store has several different variables applied and I would like to update the query and return it with the same variables. I found in the docs that updateQueries has an option to include queryVariables which are the last set of variables that the query was executed with. I have not found anything that describes how to retrieve the queryVariables or something like it from inside of

Using Apollo, how can I distinguish newly created objects?

前提是你 提交于 2019-12-11 07:17:42
问题 My use case is the following: I have a list of comments that I fetch using a GraphQL query. When the user writes a new comment, it gets submitted using a GraphQL mutation. Then I'm using updateQueries to append the new comment to the list. In the UI, I want to highlight the newly created comments. I tried to add a property isNew: true on the new comment in mutationResult , but Apollo removes the property before saving it to the store (I assume that's because the isNew field isn't requested in

apollo client delete from store without mutation

痞子三分冷 提交于 2019-12-11 02:44:26
问题 I need to remove a "record" from the local store by id without using mutation because the server does not support mutations. I have tried to access manually the store like that: delete this.apolloClient.store.getState().apollo.data['1112'] this removes the record but when I ask apollo to fetch the items it goes to the server, like there is no cache. by the way, if instead of removing I just update one of the primitive properties like that : this.apolloClient.store.getState().apollo.data['1112

Update Apollo GraphQL cache without using refetchQueries?

耗尽温柔 提交于 2019-12-11 00:27:44
问题 I have a React app accessing GraphQL server with the Apollo Client (version 1.x). There is a server schema that looks like this. type Query { currentShop: Shop } type Shop { id: ID! name: String! products: [Product!]! ...etc } I do have dataIdFromObject defined like this. const dataIdFromObject = o => { if (o.__typename != null && o.id != null) { return `${o.__typename}-${o.id}` } return null } Throughout the app, I am running queries asking for different fields of currentShop . At various

How To Pass Props From Redux Store into Apollo GraphQL Query

≯℡__Kan透↙ 提交于 2019-12-11 00:14:49
问题 I'm just getting going with Apollo GraphQL on a simple React Native app and am really impressed by what it can do. But I'm not quite wrapping my head around how it integrates with the Redux store. Essentially, I need to pass some user input from my searchReducer into my GraphQL query. I thought I could simply pass the connected component to my GraphQL query and supply a variable, but it's not finding the prop searchInput . Here's the code: import React, { Component } from 'react'; import {