GithubHelp home page GithubHelp logo

Comments (1)

magdyB7r avatar magdyB7r commented on April 29, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.