Comments (3)
I'm looking into updateQueries but have had no luck with it
That's generally the most manual approach available if the normalization isn't doing it automatically and you don't want to refetch. What's your use case and what have you tried?
from react-fullstack-graphql.
Hmmm, hokay! Here's the context:
I have an online store with a set of products that can be added to or removed from the current user's wishlist. Using this.state.isOnWishList
for optimistic feedback was fine as long as there was only one rendered component per product, but now I'm in a situation in which there can be multiple components rendered per product.
I render the product page like:
import React, { Component } from 'react';
import { graphql } from react-apollo;
const productQuery = gql`
query Product($ids: [Int]) {
products(ids: $ids) {
id
isOnWishList
...
}
}
`;
@graphql(productQuery)
class ProductPage extends Component { ... }
Now there's a WishlistButton that's deeply nested inside ProductPage:
import React, { Component } from 'react';
import { graphql } from react-apollo;
const addToWishListMutator = gql`
mutation AddToWishList($productId: Int!) {
addToWishlist (productId: $productId)
}
`;
@graphql(addToWishListMutator, { name: 'addToWishList' })
class WishListButton extends Component {
toggleWishList = (e) => {
// Omitting removal for simplicity
this.addToWishList();
}
render() {
const { product } = this.props; // passed down through the hierarchy
const { isOnWishList } = product;
return (
<button>
{ isOnWishList ? 'On Wish List' : 'Add to Wish List' }
</button>
);
}
}
Now after clicking the WishListButton, it calls addToWishList
, which makes the GraphQL mutation call. In my ideal case, just using dataIdFromObject
in the Apollo client setup should make this mutation update the corresponding product record in the cache, and the button should update to say "On Wish List"...but it doesn't. I also added an updateQueries
in the mutator decorator call, but it doesn't look like it's invoked ever. The only thing that's worked so far is explicitly defining another query productWishListQuery
and passing down productWishListQuery.refetch
to be invoked after the mutator is called.
Would you happen to know what's wrong with my setup?
from react-fullstack-graphql.
This issue is outdated. Please open a new issue if you have problems.
from react-fullstack-graphql.
Related Issues (20)
- es6 support HOT 4
- A valid environment variable to satisfy the declaration 'env:PRISMA_ENDPOINT' could not be found. HOT 2
- API of the application schema not returning nested query. HOT 1
- Errors on Start Up HOT 2
- How to query nested arrays?
- 'Create' button not working
- outdated client side
- the link is broken on readme file
- Unknown argument: boilerplate HOT 17
- How to refresh the generated server data HOT 1
- Readme is wrong. There's no such script as `yarn dev` to run the server
- There is no `react-fullstack-advanced` option HOT 5
- There's no such script as `yarn dev` to run the server - fullstack-advanced HOT 1
- TypeError: Only absolute URLs are supported HOT 3
- graphql create my-app --boilerplate react-fullstack-basic command is not working HOT 6
- Unknown argument: boilerplate HOT 2
- Project Not Found 'cluster@default'
- AC3 version?
- Action Required: Fix Renovate Configuration
- Dependency Dashboard
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-fullstack-graphql.