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 } from '@apollo/client';
    
    const cache = new InMemoryCache();
    const client = new ApolloClient({
      cache,
      resolvers: { /* ... */ },
    });
    
    function writeInitialData() {
      cache.writeQuery({
        query: gql`
          query GetTodosNetworkStatusAndFilter {
            todos
            visibilityFilter
            networkStatus {
              isConnected
            }
          }
        `,
        data: {
          todos: [],
          visibilityFilter: 'SHOW_ALL',
          networkStatus: {
            __typename: 'NetworkStatus',
            isConnected: false,
          },
        },
      });
    }
    
    writeInitialData();
    
    client.onResetStore(writeInitialData);
    Docs
  • import React from 'react';
    import ReactDOM from 'react-dom';
    import {
      ApolloClient,
      InMemoryCache,
      ApolloProvider,
      useQuery,
      gql
    } from '@apollo/client';
    
    import Pages from './pages';
    import Login from './pages/login';
    
    const cache = new InMemoryCache();
    
    const client = new ApolloClient({
      uri: 'http://localhost:4000/graphql',
      cache
    });
    
    const IS_LOGGED_IN = gql`
      query IsUserLoggedIn {
        isLoggedIn @client
      }
    `;
    
    cache.writeQuery({
      query: IS_LOGGED_IN,
      data: {
        isLoggedIn: !!localStorage.getItem("token"),
      },
    });
    
    function App() {
      const { data } = useQuery(IS_LOGGED_IN);
      return data.isLoggedIn ? <Pages /> : <Login />;
    }
    
    ReactDOM.render(
      <ApolloProvider client={client}>
        <App />
      </ApolloProvider>,
      document.getElementById("root"),
    );
    Docs
  • import React from "react";
    import { useApolloClient } from "@apollo/client";
    
    import Link from "./Link";
    
    function FilterLink({ filter, children }) {
      const client = useApolloClient();
      return (
        <Link
          onClick={() => client.writeQuery({
            query: gql`query GetVisibilityFilter { visibilityFilter }`,
            data: { visibilityFilter: filter },
          })}
        >
          {children}
        </Link>
      );
    }
    Docs
  • Powered by Official black Bloop logo with a period
    download the IDE extension

    View other examples