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 { ApolloClient, InMemoryCache } from '@apollo/client';
    
    const client = new ApolloClient({
      cache: new InMemoryCache({
        typePolicies: {
          Query: {
            fields: {
              book: {
                read(_, { args, toReference }) {
                  return toReference({
                    __typename: 'Book',
                    id: args.id,
                  });
                }
              }
            }
          }
        }
      })
    });
    Docs
  • import { ApolloClient, InMemoryCache, gql } from '@apollo/client';
    
    let nextTodoId = 0;
    
    const cache = new InMemoryCache();
    
    cache.writeQuery({
      query: gql`query GetTodos { todos { ... } }`,
      data: { todos: [] },
    });
    
    const client = new ApolloClient({
      resolvers: {
        Mutation: {
          addTodo: (_, { text }, { cache }) => {
            const query = gql`
              query GetTodos {
                todos @client {
                  id
                  text
                  completed
                }
              }
            `;
    
            const previous = cache.readQuery({ query });
            const newTodo = { id: nextTodoId++, text, completed: false, __typename: 'TodoItem' };
            const data = {
              todos: [...previous.todos, newTodo],
            };
    
            cache.writeQuery({ query, data });
            return newTodo;
          },
        },
      },
    });
    Docs
  • import { ApolloClient, InMemoryCache } from '@apollo/client';
    
    const client = new ApolloClient({
      cache: new InMemoryCache(),
      resolvers: {
        Mutation: {
          updateVisibilityFilter: (_, { visibilityFilter }, { cache }) => {
            cache.writeQuery({
              query: gql`query GetVisibilityFilter { visibilityFilter }`,
              data: {
                __typename: 'Filter',
                visibilityFilter,
              },
            });
          },
        },
      },
    };
    Docs
  • Powered by Official black Bloop logo with a period
    download the IDE extension

    View other examples