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

  • const query = gql`
      query MyTodoAppQuery {
        todos {
          id
          text
          completed
        }
      }
    `;
    
    // Get the current to-do list
    const data = client.readQuery({ query });
    
    const myNewTodo = {
      id: '6',
      text: 'Start using Apollo Client.',
      completed: false,
      __typename: 'Todo',
    };
    
    // Write back to the to-do list and include the new item
    client.writeQuery({
      query,
      data: {
        todos: [...data.todos, myNewTodo],
      },
    });
    Docs
  • // Query that fetches all existing to-do items
    const query = gql`
      query MyTodoAppQuery {
        todos {
          id
          text
          completed
        }
      }
    `;
    
    // Get the current to-do list
    const data = client.readQuery({ query });
    
    // Create a new to-do item
    const myNewTodo = {
      id: '6',
      text: 'Start using Apollo Client.',
      completed: false,
      __typename: 'Todo',
    };
    
    // Write back to the to-do list, appending the new item
    client.writeQuery({
      query,
      data: {
        todos: [...data.todos, myNewTodo],
      },
    });
    Docs
  • import { ApolloClient, InMemoryCache, HttpLink, gql } from '@apollo/client';
    
    const query = gql`
      query CurrentAuthorPostCount($authorId: Int!) {
        currentAuthor @client {
          name
          authorId @export(as: "authorId")
        }
        postCount(authorId: $authorId)
      }
    `;
    
    const cache = new InMemoryCache();
    const client = new ApolloClient({
      link: new HttpLink({ uri: 'http://localhost:4000/graphql' }),
      cache,
      resolvers: {},
    });
    
    cache.writeQuery({
      query: gql`
        query GetCurrentAuthor {
          currentAuthor {
            name
            authorId
          }
        }
      `,
      data: {
        currentAuthor: {
          __typename: 'Author',
          name: 'John Smith',
          authorId: 12345,
        },
      },
    });
    
    // ... run the query using client.query, the <Query /> component, etc.
    Docs
  • import { ApolloClient, InMemoryCache, HttpLink, gql } from '@apollo/client';
    
    const query = gql`
      query CurrentAuthorPostCount($authorId: Int!) {
        currentAuthorId @client @export(as: "authorId")
        postCount(authorId: $authorId)
      }
    `;
    
    const cache = new InMemoryCache();
    const client = new ApolloClient({
      link: new HttpLink({ uri: 'http://localhost:4000/graphql' }),
      cache,
      resolvers: {},
    });
    
    cache.writeQuery({
      query: gql`query GetCurrentAuthorId { currentAuthorId }`,
      data: {
        currentAuthorId: 12345,
      },
    });
    
    // ... run the query using client.query, the <Query /> component, etc.
    Docs
  • import { ApolloClient, InMemoryCache, HttpLink, gql } from '@apollo/client';
    
    const query = gql`
      query CurrentAuthorPostCount($authorId: Int!) {
        currentAuthorId @client @export(as: "authorId")
        postCount(authorId: $authorId) @client
      }
    `;
    
    const cache = new InMemoryCache();
    const client = new ApolloClient({
      cache,
      resolvers: {
        Query: {
          postCount(_, { authorId }) {
            return authorId === 12345 ? 100 : 0;
          },
        },
      },
    });
    
    cache.writeQuery({
      query: gql`{ currentAuthorId }`,
      data: {
        currentAuthorId: 12345,
      },
    });
    
    // ... run the query using client.query, the <Query /> component, etc.
    Docs
  • Powered by Official black Bloop logo with a period
    download the IDE extension

    View other examples