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 { gql } from "apollo-boost";
    // or you can use `import gql from 'graphql-tag';` instead
    
    ...
    
    client
      .query({
        query: gql`
          {
            rates(currency: "USD") {
              currency
            }
          }
        `
      })
      .then(result => console.log(result));
    Docs
  • import { gql, useLazyQuery } from "@apollo/client";
    
    const GET_GREETING = gql`
      query GetGreeting($language: String!) {
        greeting(language: $language) {
          message
        }
      }
    `;
    
    function Hello() {
      const [loadGreeting, { called, loading, data }] = useLazyQuery(
        GET_GREETING,
        { variables: { language: "english" } }
      );
      if (called && loading) return <p>Loading ...</p>
      if (!called) {
        return <button onClick={() => loadGreeting()}>Load greeting</button>
      }
      return <h1>Hello {data.greeting.message}!</h1>;
    }
    Docs
  • import { gql, useQuery } from '@apollo/client';
    
    const GET_GREETING = gql`
      query GetGreeting($language: String!) {
        greeting(language: $language) {
          message
        }
      }
    `;
    
    function Hello() {
      const { loading, error, data } = useQuery(GET_GREETING, {
        variables: { language: 'english' },
      });
      if (loading) return <p>Loading ...</p>;
      return <h1>Hello {data.greeting.message}!</h1>;
    }
    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 ReactDOM from "react-dom";
    import {
      ApolloClient,
      InMemoryCache,
      HttpLink,
      ApolloProvider,
      useQuery,
      gql
    } from "@apollo/client";
    
    import Pages from "./pages";
    import Login from "./pages/login";
    
    const cache = new InMemoryCache();
    const client = new ApolloClient({
      cache,
      link: new HttpLink({ uri: "http://localhost:4000/graphql" }),
      resolvers: {},
    });
    
    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
  • Powered by Official black Bloop logo with a period
    download the IDE extension

    View other examples