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

  • function ExchangeRates() {
      const { loading, error, data } = useQuery(EXCHANGE_RATES);
      if (loading) return 

    Loading...

    ; if (error) return

    Error :(

    ; return data.rates.map(({ currency, rate }) => (

    {currency}: {rate}

    )); }
    Docs
    0
  • const { loading, error, data } = useQuery(GET_DOGS, {
      fetchPolicy: "no-cache",
    });
    
    Docs
    0
  • function ExchangeRates() {
      const { loading, error, data } = useQuery(EXCHANGE_RATES);
      if (loading) return 

    Loading...

    ; if (error) return

    Error :(

    ; return data.rates.map(({ currency, rate }) => (

    {currency}: {rate}

    )); }
    Docs
    0
  • const GET_DOG = gql`
      query GetDog($dogId: ID!) {
        dog(id: $dogId) {
          name
          breed
        }
      }
    `;
    
    function Dog({ id }) {
      const { loading, error, data } = useQuery(GET_DOG, {
        variables: { dogId: id },
      }); // ...render component...
    }
    
    Docs
    0
  • import React from "react";
    import {
      ApolloConsumer,
      useApolloClient,
      useQuery,
      gql,
    } from "@apollo/client";
    
    const GET_MESSAGE_COUNT = gql`
      query GetMessageCount {
        messageCount @client {
          total
        }
      }
    `;
    
    const resolvers = {
      Query: {
        messageCount: (_, args, { cache }) => {
          // ... calculate and return the number of messages in
          // the cache ...
          return {
            total: 123,
            __typename: "MessageCount",
          };
        },
      },
    };
    
    export function MessageCount() {
      const client = useApolloClient();
      client.addResolvers(resolvers);
    
      const {
        loading,
        data: { messageCount },
      } = useQuery(GET_MESSAGE_COUNT);
    
      if (loading) return "Loading ...";
    
      return (
        

    Total number of messages: {messageCount.total}

    ); }
    Docs
    0
  • function App() {
      const { data } = useQuery(IS_LOGGED_IN);
      return data.isLoggedIn ?  : ;
    }
    
    Docs
    0
  • import { GET_CART_ITEMS } from "./pages/cart";
    
    export const resolvers = {
      Launch: {
        isInCart: (launch, _, { cache }) => {
          const { cartItems } = cache.readQuery({
            query: GET_CART_ITEMS,
          });
          return cartItems.includes(launch.id);
        },
      },
    };
    
    Docs
    0
  • 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  component, etc.
    
    Docs
    0
  •   resolvers: {
        Launch: {
          isInCart: (launch, _args, { cache }) => {
            const { cartItems } = cache.readQuery({ query: GET_CART_ITEMS });
            return cartItems.includes(launch.id);
          },
        },
      },
    Docs
    0
  • import React from "react";
    import {
      ApolloConsumer,
      useApolloClient,
      useQuery,
      gql,
    } from "@apollo/client";
    
    const GET_MESSAGE_COUNT = gql`
      query GetMessageCount {
        messageCount @client {
          total
        }
      }
    `;
    
    const resolvers = {
      Query: {
        messageCount: (_, args, { cache }) => {
          // ... calculate and return the number of messages in
          // the cache ...
          return {
            total: 123,
            __typename: "MessageCount",
          };
        },
      },
    };
    
    export function MessageCount() {
      const client = useApolloClient();
      client.addResolvers(resolvers);
    
      const {
        loading,
        data: { messageCount },
      } = useQuery(GET_MESSAGE_COUNT);
    
      if (loading) return "Loading ...";
    
      return (
        

    Total number of messages: {messageCount.total}

    ); }
    Docs
    0
  • import {
      ApolloClient,
      InMemoryCache,
    } from "@apollo/client";
    import { withClientState } from "apollo-link-state";
    
    import { resolvers, defaults } from "./resolvers";
    
    const cache = new InMemoryCache();
    const stateLink = withClientState({
      cache,
      resolvers,
      defaults,
    });
    
    const client = new ApolloClient({
      cache,
      link: stateLink,
    });
    
    client.onResetStore(stateLink.writeDefaults);
    
    Docs
    0
  • 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
    0
  • Powered by Official black Bloop logo with a period
    download the IDE extension

    View other examples