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 client = new ApolloClient({
      cache: new InMemoryCache(),
      resolvers: { ... },
      typeDefs: { ... },
    });
    Docs
  • 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 (
        <p>
          Total number of messages: {messageCount.total}
        </p>
      );
    };
    Docs
  • 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
  • import { ApolloClient, InMemoryCache, gql } from '@apollo/client';
    
    const client = new ApolloClient({
      cache: new InMemoryCache(),
      resolvers: {
        Query: {
          isLoggedIn() {
            return !!localStorage.getItem('token');
          },
        },
      },
    });
    
    const IS_LOGGED_IN = gql`
      query IsUserLoggedIn {
        isLoggedIn @client(always: true)
      }
    `;
    
    // ... run the query using client.query, a <Query /> component, etc.
    Docs
  • import { ApolloClient, InMemoryCache } from '@apollo/client';
    
    const client = new ApolloClient({
      cache: new InMemoryCache(),
      resolvers: {
        Mutation: {
          updateUserEmail: (_, { id, email }, { cache }) => {
            cache.writeFragment({
              id: cache.identify({ __typename: "User", id }),
              fragment: gql`fragment UserEmail on User { email }`,
              data: { email },
            });
          },
        },
      },
    };
    Docs
  • Powered by Official black Bloop logo with a period
    download the IDE extension

    View other examples