Comments (1)
I was migrating to ac3 but stuck with using the client to get remote data like resolvers just like those two examples
here I need the client to get the active template from the server, how can I get the client with typePolicies?
getColors: {
async read(_, {cache}) {
const template = await getActiveTemplate(cache,client);
if (!template) {
return {};
}
const settings = template.settings ? JSON.parse(template.settings) : [];
const colors = settings.find((setting) => setting.type === 'colors');
if (!colors) {
return {};
}
let colorConfig = {};
forEach(colors.fields, (color) => {
colorConfig = Object.assign({}, colorConfig, {
[color.key]: color.value,
});
});
return colorConfig;
},
},
and here with mutation same, I need the client
export const cartMutation = {
addProductToCart: (_root, {product}, {cache, client}) => {
const cart = cartItems();
const {status, message, newCart} = checkItemAddCart(cart, product);
updateCart(cache, newCart);
authCart(client, {quantity: 1, productId: product.id}, newCart);
}
// const newCart = addProductToCart(cart, product);
// localStorage.setItem("CartItems", JSON.stringify(newCartItems));
// const {me} = client.cache.readQuery({
// query: CURRENT_CUSTOMER,
// });
return newCart;
},
}
the ugly solution with this is
const client = useApolloClient();
cartMutation.addProductToCart(client);
how can I use client easily with those two examples?
from ac3-state-management-examples.
Related Issues (11)
- Assets HOT 1
- How to display values from database in real time with apollo client 3 and react js?
- Reactive variables and HMR (hot module reloading) / fast-refresh HOT 3
- Persisting cache to localstorage
- JSX examples - Moving from Redux to Apollo Client 3
- Looking for example of pagination using custom field types (relay)
- Property 'onNextChange' is missing in type HOT 3
- Looking for example with remote data combined with local data
- Strategy to make the local state persisting HOT 6
- the cache empty when running the apollo-local-state project
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 ac3-state-management-examples.