react-apollo

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 =

nested object in graphcool

∥☆過路亽.° 提交于 2019-12-11 17:35:08
问题 I have a model like this: type User @model { id: ID! @isUnique } Now I want to add a nested object: type User @model { id: ID! @isUnique position: { lat: Int lng: Int } } but I get a error from Graphcool, {", expected IgnoredNoComment, ImplementsInterfaces or Directives (line 4, column 11): type User @model { ^ Why? can't I pass a nested object? In this way I can update the mutation simply passing the object with lat and lng. What is wrong with this? 回答1: For nested structure you need to

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

How to deploy Next.js with GraphQL backend on Zeit Now?

牧云@^-^@ 提交于 2019-12-11 11:47:03
问题 I have an Next.js/Express/Apollo GraphQL app running fine on localhost. I try to deploy it on Zeit Now, and the Next.js part works fine, but the GraphQL backend fails because /graphql route returns: 502: An error occurred with your deployment Code: NO_STATUS_CODE_FROM_LAMBDA My now.json looks like: { "version": 2, "builds": [ { "src": "next.config.js", "use": "@now/next" }, { "src": "server/server.js", "use": "@now/node" } ], "routes": [ { "src": "/api/(.*)", "dest": "server/server.js" }, {

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

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 {

How to use data from readFragment in Apollo?

爷,独闯天下 提交于 2019-12-10 23:37:45
问题 After a login mutation, a jwt token and a user object (id and firstName) are returned and stored in cache (as shown in the image below). I want to retrieve the user informations from the cache by using readFragment and pass it to Layout component. So I've tried to use read Fragment in my Layout component like this : class Layout extends Component { render() { const test = this.props.client.readFragment({ id: 1, // `id` is any id that could be returned by `dataIdFromObject`. fragment: gql`

Apollo: data / mutation prop not passed to component

随声附和 提交于 2019-12-10 21:06:18
问题 I have the following component with a query and a mutation, but my Component does not receive the data and the mutation prop. Am I doing something wrong or missing in my code? The query does get executed though, it's just not passed down. this.props.mutate as well as this.props.data is undefined. class ResetConfirm extends React.Component { static propTypes = { intl: intlShape.isRequired, token: React.PropTypes.string, data: React.PropTypes.shape({ loading: React.PropTypes.bool.isRequired,

React Apollo dynamically create query from state

自古美人都是妖i 提交于 2019-12-10 19:03:56
问题 Heres a model situation I have some fields in my DB lets say color,size,height ... I can fetch and display these fields to user who can choose these fields and they are afterwards set to components state What i want to achieve is to dynamically create GQL query (not query variables) from these fields stored in state Example //import react gql .... class MyComponent extends Component { constructor(props){ super(props) this.state = { fields : [] } } render(){ ... } componentWillMount(){ fetch(.