How to use where clause in Knex
Create refunds with Stripe
Load HTML with Cheerio
How to send POST request with Axios
Find intersection of array in Lodash
Powered by Official white Bloop logo with a period

Terms / Privacy / Search / Support

  • import { ApolloClient, InMemoryCache, HttpLink, gql } from '@apollo/client';
    
    const GET_CART_ITEMS = gql`
      query GetCartItems {
        cartItems @client
      }
    `;
    
    const cache = new InMemoryCache();
    cache.writeQuery({
      query: GET_CART_ITEMS,
      data: {
        cartItems: [],
      },
    });
    
    const client = new ApolloClient({
      cache,
      link: new HttpLink({
        uri: 'http://localhost:4000/graphql',
      }),
      resolvers: {
        Launch: {
          isInCart: (launch, _args, { cache }) => {
            const { cartItems } = cache.readQuery({ query: GET_CART_ITEMS });
            return cartItems.includes(launch.id);
          },
        },
      },
    });
    
    const GET_LAUNCH_DETAILS = gql`
      query LaunchDetails($launchId: ID!) {
        launch(id: $launchId) {
          isInCart @client
          site
          rocket {
            type
          }
        }
      }
    `;
    
    // ... run the query using client.query, a <Query /> component, etc.
    Docs
  • import { InMemoryCache } from '@apollo/client';
    
    const cache = new InMemoryCache();
    cache.writeQuery({
      query: gql`query MyQuery {
        isLoggedIn,
        cartItems
      }`,
      data: {
        isLoggedIn: !!localStorage.getItem('token'),
        cartItems: [],
      },
    });
    Docs
  • import { useReactiveVar } from '@apollo/client';
    
    export function Cart() {
      const cartItems = useReactiveVar(cartItemsVar);
    
      return (
        <div class="cart">
          <Header>My Cart</Header>
          {cartItems.length === 0 ? (
            <p>No items in your cart</p>
          ) : (
            <Fragment>
              {cartItems.map(productId => (
                <CartItem key={productId} />
              ))}
            </Fragment>
          )}
        </div>
      );
    }
    Docs
  • export const GET_CART_ITEMS = gql`
      query GetCartItems {
        cartItems @client
      }
    `;
    
    export function Cart() {
      const { data, loading, error } = useQuery(GET_CART_ITEMS);
    
      if (loading) return <Loading />;
      if (error) return <p>ERROR: {error.message}</p>;
    
      return (
        <div class="cart">
          <Header>My Cart</Header>
          {data && data.cartItems.length === 0 ? (
            <p>No items in your cart</p>
          ) : (
            <Fragment>
              {data && data.cartItems.map(productId => (
                <CartItem key={productId} />
              ))}
            </Fragment>
          )}
        </div>
      );
    }
    Docs
  • client.writeQuery({
        query: gql`
          query GetCartItems {
            cartItems
          }
        `,
        data: {
          cartItems: []
        }
      });
    Docs
  • Powered by Official black Bloop logo with a period
    download the IDE extension

    View other examples